Compile error in juce_String.h

I have successfully compiled my plugin many times before, but now when I compile my plugin on macOS, I am now getting this error compiling juce_String.h:

920   static String formatted (const String& formatStr, Args... args)      { return formattedRaw (formatStr.toRawUTF8(), args...); }

Cannot pass object of non-trivial type 'juce::String' through variadic function; call will abort at runtime

I am running:
macOS 13.6 Ventura
JUCE 7.0.9 (the latest version as far as I know)
xCode 15.2 (the latest version as far as I know)

I am rebuilding my project from scratch using the Projucer and then immediately getting the compiler error when I try to compile, so I don’t think it’s because I’ve messed up in xCode.

I don’t know what to do about this.

I have just created a brand new Projucer project and just did “File > New Project…” and it generated an xCode project and I opened xCode and it compiled with no errors. So this eliminates the possibility that I have corrupted JUCE source code in my JUCE installation.

In the problematic project, I’m regenerating the whole project in the Projucer before attempting to compile, so that eliminates the chance that I’ve stuffed up some xCode settings in my project, because the whole xCode project file is being deleted and regenerated by the Projucer before each attempt to compile. However, I might have stuffed up some Projucer project settings somehow.

The docs for String::formatted say:

make sure that you never, ever, pass any String objects to [the function] as parameters. And bear in mind that internally, depending on the platform, it may be using wchar_t or char character types, so that even string literals can’t be safely used as parameters if you’re writing portable code.

Based on the error message you’re seeing, it sounds like you’re passing a String to String::formatted, which is not supported. Instead of using String::formatted, consider using << to build strings.

Thanks. I found the problem. It was this line in new code I had written recently:

 x += String::formatted("Channel Name = %s%",channel_to_channel_name(channel_kind)) + "\n";

where channel_to_channel_name() was yielding an object of type juce::String.

The reason why I got so completely stumped by this is because the compiler error was pointing at
the function BEING CALLED not at the function call point. So I automatically assumed that it was a compilation error in the JUCE library code and not my fault at all. I have never seen this behaviour (pointing to the function being called when the problem is in the function’s invocation) in a compiler ever before.

Thanks so much for helping. Based on the error message, you kind of pointed out the obvious because that’s what the error message was saying, but it was so non-obvious to me that a compiler would ever point to the function being called and not to the erroneous function invocation point that I needed the obvious spelt out explicitly. So thanks.