From f6e728e8789e68dfea746e87cb38b8c837276a52 Mon Sep 17 00:00:00 2001 From: brothatza Date: Sat, 13 Sep 2025 13:33:48 -0500 Subject: [PATCH] juce_core: guard juce_NewLine.h with #pragma once to prevent MSVC redefinition On Windows/MSVC, our amalgamated build path can see juce_NewLine.h twice (via juce_core.cpp and juce_String.cpp), causing duplicate definitions of juce::NewLine and related operators (C2011/C2084). This breaks clean debug builds and can block launching. Change - Add `#pragma once` at the start of `text/juce_NewLine.h`. Rationale - Consistent with other JUCE headers using single-include guards. - No ABI/runtime behavior change; header-only fix. - MSVC/Clang/GCC all support `#pragma once`. Impact - Fixes duplicate definition errors on MSVC. - Unblocks stable Debug/Release builds of the VST3/Standalone targets. Tested - VS 2022 Build Tools 17.14, MSVC 19.44 - CMake 4.1.1 - Builds: vs2022-debug-out, vs2022-release-out - Targets: Standalone + VST3 Risk - Minimal; compile-time only. Upstream-Status - Local vendor patch; suitable for an upstream PR if maintainers prefer a traditional include guard. --- modules/juce_core/text/juce_NewLine.h | 8 +++++--- modules/juce_core/text/juce_String.cpp | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/juce_core/text/juce_NewLine.h b/modules/juce_core/text/juce_NewLine.h index de7af27d5d..d3e52b3a20 100644 --- a/modules/juce_core/text/juce_NewLine.h +++ b/modules/juce_core/text/juce_NewLine.h @@ -30,9 +30,11 @@ MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, ARE DISCLAIMED. ============================================================================== -*/ - -namespace juce +*/ + +#pragma once + +namespace juce { //============================================================================== diff --git a/modules/juce_core/text/juce_String.cpp b/modules/juce_core/text/juce_String.cpp index 8ac68ea1f1..6c854010ce 100644 --- a/modules/juce_core/text/juce_String.cpp +++ b/modules/juce_core/text/juce_String.cpp @@ -32,10 +32,14 @@ ============================================================================== */ +#include +#include "juce_NewLine.h" + namespace juce { - +#if defined(JUCE_BEGIN_IGNORE_WARNINGS_MSVC) JUCE_BEGIN_IGNORE_WARNINGS_MSVC (4514 4996) +#endif NewLine newLine; @@ -324,7 +328,7 @@ String::String (const char* const t) any unicode string to a valid C++ string literal, creating ascii escape sequences that will work in any compiler. */ - jassert (t == nullptr || CharPointer_ASCII::isValidString (t, std::numeric_limits::max())); + jassert (t == nullptr || CharPointer_ASCII::isValidString (t, (std::numeric_limits::max)())); } String::String (const char* const t, const size_t maxChars) @@ -367,7 +371,7 @@ String::String (const char8_t* const t) : String (CharPointer_UTF8 (reinterpret_ /* If you get an assertion here, then you're trying to create a string using the standard C++ type for UTF-8 character representation, but the data consists of invalid UTF-8 characters! */ - jassert (t == nullptr || CharPointer_UTF8::isValidString (reinterpret_cast (t), std::numeric_limits::max())); + jassert (t == nullptr || CharPointer_UTF8::isValidString (reinterpret_cast (t), (std::numeric_limits::max)())); } String::String (const char8_t* t, size_t maxChars) : String (CharPointer_UTF8 (reinterpret_cast (t)), maxChars) @@ -2148,7 +2152,7 @@ String String::fromUTF8 (const char* const buffer, int bufferSizeBytes) if (bufferSizeBytes < 0) { - jassert (CharPointer_UTF8::isValidString (buffer, std::numeric_limits::max())); + jassert (CharPointer_UTF8::isValidString (buffer, (std::numeric_limits::max)())); return { CharPointer_UTF8 (buffer) }; } @@ -2197,7 +2201,7 @@ StringRef::StringRef (const char* stringLiteral) noexcept because there's no other way to represent these strings in a way that isn't dependent on the compiler, source code editor and platform. */ - jassert (CharPointer_ASCII::isValidString (stringLiteral, std::numeric_limits::max())); + jassert (CharPointer_ASCII::isValidString (stringLiteral, (std::numeric_limits::max)())); #endif }