<div dir="ltr">Digging into the implementation (Sema::BuildObjCLiteral), I see two things:<div> - the class is found by name lookup, so introducing an alias should work</div><div> - the behavior depends on another flag, -fno-constant-cfstrings</div><div>   - when this flag is passed, -fconstant-string-class is used, falling back to "NSConstantString"</div><div>   - when this flag is not passed, "NSString" is always used</div><div><br></div><div>So two possible workarounds:</div><div> - add `@comptability_alias NSString NGStringLiteral;` to your header</div><div> - pass -fno-constant-cfstrings -fconstant-string-class=NGStringLiteral</div><div><br></div><div>I don't have any deep understanding here, so I don't know *why* these interactions exist, or which option you should choose. I'd guess the latter, though.</div><div>And AFAIK this should always be the same between (equal versions of) clang and clangd, so let me know if you can verify differences.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 4, 2019 at 9:28 AM Sam McCall <<a href="mailto:sammccall@google.com">sammccall@google.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">FWIW, I get this error from clang too:<div><br></div><div>$ cat str.m</div><div><br></div><div>@interface NGStaticObject<br>{ Class isa; }<br>@end<br>@interface NGStringLiteral : NGStaticObject<br>{ char *c_string; unsigned int len; }<br>@end<br>NGStringLiteral *t = @"Hello world";<br></div><div><br></div><div>$ clang-7 -fsyntax-only str.m -fconstant-string-class=NGStringLiteral</div><div><br></div><div>str.m:7:18: warning: incompatible pointer types initializing 'NGStringLiteral *' with an expression of type 'NSString *' [-Wincompatible-pointer-types]<br></div><div><br></div><div>$ clang-7 --version</div><div><br></div><div>clang version 7.0.1-6 (tags/RELEASE_701/final)<br>Target: x86_64-pc-linux-gnu<br>Thread model: posix<br>InstalledDir: /usr/bin<br></div><div><br></div><div>Similar results from tip-of-tree.</div><div><br></div><div>How are you running clang, and what's your clang --version?</div><div><br></div><div>This may well need a solution regardless, but it'd be good to know if it's really clangd-specific (which would be surprising).</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Jul 4, 2019 at 7:54 AM Andreas Ostermeyer <<a href="mailto:ostermeyer@me.com" target="_blank">ostermeyer@me.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div>Hi Sam,<div><br></div><div>thanks for rapid responding. Yes, you’re right. I’ve forgotten to provide some descriptive code.</div><div><br></div><div>I’ve issued the constant-string-class flag in both files: compile_flags.txt at first and than in compile_commands.json to no avail.</div><div><br></div><div>NGStringLiteral is declared exactly like NXConstantString and demanded in the LLVM documentation, i.e. Class, char*, and unsigned int. Like so:</div><div><div><br></div><div><font face="Courier">@interface NGStaticObject</font></div><div><font face="Courier">{</font></div><div><font face="Courier">  Class isa; /* A pointer to the instance's class structure.  */</font></div><div><font face="Courier">}</font></div><div><font face="Courier">...</font></div><div><font face="Courier">@end</font></div></div><div><div><font face="Courier"><br></font></div><div><font face="Courier">@interface NGStringLiteral : NGStaticObject</font></div><div><font face="Courier">{</font></div><div><font face="Courier">  char *c_string;</font></div><div><font face="Courier">  unsigned int len;</font></div><div><font face="Courier">}</font></div><div><font face="Courier">@end</font></div></div><div><br></div><div>The test code in question is:</div><div><br></div><div><font face="Courier">NGStringLiteral *test0 = @"Hello world”;<span class="gmail-m_5248522066097801276gmail-m_3278666265252383080Apple-tab-span" style="white-space:pre-wrap">       </span>// —> “Incompatible pointer types initializing 'NGStringLiteral *' with an expression of type 'NSString *’”</font></div><div><br></div><div>A first attempt to mitigate this was:</div><div><br></div><div><font face="Courier">typedef NGStringLiteral NSString;</font></div><div><div><font face="Courier">NSString *test1 = @"That's me;)”;<span class="gmail-m_5248522066097801276gmail-m_3278666265252383080Apple-tab-span" style="white-space:pre-wrap">      </span>// —> “Incompatible pointer types initializing 'NSString *' (aka 'NGStringLiteral *') with an expression of type 'NSString *’”</font></div><div><br></div><div>Another attempt is subclassing NSString from NGStringLiteral. This quiets clangd, but now the compiler (gcc) complains “warning: initialization from distinct Objective-C type”. But this is another story.</div><div><br></div><div>All the above code would be irrelevant if clangd would regard the constant-string-class flag.</div><div><br></div><div>Cheers,</div><div><br></div><div>Andreas</div><div><br><blockquote type="cite"><div>On 3. Jul 2019, at 21:08, Sam McCall <<a href="mailto:sammccall@google.com" target="_blank">sammccall@google.com</a>> wrote:</div><br class="gmail-m_5248522066097801276gmail-m_3278666265252383080Apple-interchange-newline"><div><div dir="auto"><div>Hi Andreas,</div><div dir="auto"><br><div dir="auto">Can you provide a minimal source file that exhibits the problem, and explain how you're specifying the -fconstant-string-class flag? (It should be in the compile_commands.json or compile_flags.txt file)</div><div dir="auto"><br></div><div dir="auto">It sounds like what you're describing should work, but I think we need more detail to reproduce the issue.</div><div dir="auto"><br></div><div dir="auto"> I cant really speak to the layering between objc the language and the Foundation etc libraries. I'm sympathetic to the frustration but realistically clangd won't diverge from clang here, so this would be an issue for experts on cfe-dev.</div><div dir="auto"><br></div><div dir="auto">Cheers, Sam</div><br><br><div class="gmail_quote" dir="auto"><div dir="ltr" class="gmail_attr">On Wed, Jul 3, 2019, 7:57 PM Andreas Ostermeyer via clangd-dev <<a href="mailto:clangd-dev@lists.llvm.org" target="_blank">clangd-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">clangd developers,<br>
<br>
currently I’m working on an own small footprint Objective-C Class library completely unrelated to Cocoa. I use clangd [version 8.0.0 (tags/RELEASE_800/final)] from homebrew as the language server in my IDE.<br>
<br>
Unfortunately I can’t clangd persuade to accept my own as a constant string class with the flag "-fconstant-string-class=NGStringLiteral". Ignoring the flag it complains: “Incompatible pointer types initializing 'NGStringLiteral *' with an expression of type 'NSString *’”.<br>
<br>
To quiet this I declared ’NSString’ as ’NGStringLiteral’ (“typedef NSString NGStringLiteral”). Now clangd warns: “Incompatible pointer types initializing 'NSString *' (aka 'NGStringLiteral *') with an expression of type 'NSString *’”!<br>
<br>
That’s annoying - like all the hard-wired Cocoa aka Apple stuff in clang software. Objective-C is an independent general purpose programming language. Not a Cocoa development tool and not an Apple software product. This should be true for clang, too.<br>
<br>
So, what can I do (or what can you do) to get rid of - at least - this?<br>
<br>
Thanks in advance.<br>
<br>
Best regards,<br>
<br>
Andreas Ostermeyer<br>
_______________________________________________<br>
clangd-dev mailing list<br>
<a href="mailto:clangd-dev@lists.llvm.org" rel="noreferrer" target="_blank">clangd-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev" rel="noreferrer noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/clangd-dev</a><br>
</blockquote></div></div></div>
</div></blockquote></div><br></div></div></blockquote></div>
</blockquote></div>