<div class="gmail_quote">On Tue, Mar 6, 2012 at 7:22 PM, Jordan Rose <span dir="ltr"><<a href="mailto:jrose@belkadan.com">jrose@belkadan.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Can this have a fixit, since almost always the right fix is a space?<br></blockquote><div><br></div><div>Not only can it, it already does :-)</div><div><br></div><div>I've added a test for the fixit in r152199.</div><div>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Jordy<br>
<div class="HOEnZb"><div class="h5"><br>
<br>
On Mar 6, 2012, at 19:13, Richard Smith wrote:<br>
<br>
> Author: rsmith<br>
> Date: Tue Mar  6 21:13:00 2012<br>
> New Revision: 152198<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=152198&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=152198&view=rev</a><br>
> Log:<br>
> Add -Wc++11-compat warning for string and character literals followed by<br>
> identifiers, in cases where those identifiers would be treated as<br>
> user-defined literal suffixes in C++11.<br>
><br>
> Modified:<br>
>    cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td<br>
>    cfe/trunk/lib/Lex/Lexer.cpp<br>
>    cfe/trunk/test/SemaCXX/cxx0x-compat.cpp<br>
><br>
> Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=152198&r1=152197&r2=152198&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=152198&r1=152197&r2=152198&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)<br>
> +++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Tue Mar  6 21:13:00 2012<br>
> @@ -131,6 +131,9 @@<br>
> def warn_cxx98_compat_unicode_literal : Warning<<br>
>   "unicode literals are incompatible with C++98">,<br>
>   InGroup<CXX98Compat>, DefaultIgnore;<br>
> +def warn_cxx11_compat_user_defined_literal : Warning<<br>
> +  "identifier after literal will be treated as a user-defined literal suffix "<br>
> +  "in C++11">, InGroup<CXX11Compat>, DefaultIgnore;<br>
> def err_unsupported_string_concat : Error<<br>
>   "unsupported non-standard concatenation of string literals">;<br>
> def err_string_concat_mixed_suffix : Error<<br>
><br>
> Modified: cfe/trunk/lib/Lex/Lexer.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=152198&r1=152197&r2=152198&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Lexer.cpp?rev=152198&r1=152197&r2=152198&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Lex/Lexer.cpp (original)<br>
> +++ cfe/trunk/lib/Lex/Lexer.cpp Tue Mar  6 21:13:00 2012<br>
> @@ -1574,14 +1574,21 @@<br>
> }<br>
><br>
> /// LexUDSuffix - Lex the ud-suffix production for user-defined literal suffixes<br>
> -/// in C++11.<br>
> +/// in C++11, or warn on a ud-suffix in C++98.<br>
> const char *Lexer::LexUDSuffix(Token &Result, const char *CurPtr) {<br>
> -  assert(getFeatures().CPlusPlus0x && "ud-suffix only exists in C++11");<br>
> +  assert(getFeatures().CPlusPlus);<br>
><br>
>   // Maximally munch an identifier. FIXME: UCNs.<br>
>   unsigned Size;<br>
>   char C = getCharAndSize(CurPtr, Size);<br>
>   if (isIdentifierHead(C)) {<br>
> +    if (!getFeatures().CPlusPlus0x) {<br>
> +      if (!isLexingRawMode())<br>
> +        Diag(CurPtr, diag::warn_cxx11_compat_user_defined_literal)<br>
> +          << FixItHint::CreateInsertion(getSourceLocation(CurPtr), " ");<br>
> +      return CurPtr;<br>
> +    }<br>
> +<br>
>     Result.setFlag(Token::HasUDSuffix);<br>
>     do {<br>
>       CurPtr = ConsumeChar(CurPtr, Size, Result);<br>
> @@ -1631,7 +1638,7 @@<br>
>   }<br>
><br>
>   // If we are in C++11, lex the optional ud-suffix.<br>
> -  if (getFeatures().CPlusPlus0x)<br>
> +  if (getFeatures().CPlusPlus)<br>
>     CurPtr = LexUDSuffix(Result, CurPtr);<br>
><br>
>   // If a nul character existed in the string, warn about it.<br>
> @@ -1714,7 +1721,7 @@<br>
>   }<br>
><br>
>   // If we are in C++11, lex the optional ud-suffix.<br>
> -  if (getFeatures().CPlusPlus0x)<br>
> +  if (getFeatures().CPlusPlus)<br>
>     CurPtr = LexUDSuffix(Result, CurPtr);<br>
><br>
>   // Update the location of token as well as BufferPtr.<br>
> @@ -1801,7 +1808,7 @@<br>
>   }<br>
><br>
>   // If we are in C++11, lex the optional ud-suffix.<br>
> -  if (getFeatures().CPlusPlus0x)<br>
> +  if (getFeatures().CPlusPlus)<br>
>     CurPtr = LexUDSuffix(Result, CurPtr);<br>
><br>
>   // If a nul character existed in the character, warn about it.<br>
><br>
> Modified: cfe/trunk/test/SemaCXX/cxx0x-compat.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-compat.cpp?rev=152198&r1=152197&r2=152198&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx0x-compat.cpp?rev=152198&r1=152197&r2=152198&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/SemaCXX/cxx0x-compat.cpp (original)<br>
> +++ cfe/trunk/test/SemaCXX/cxx0x-compat.cpp Tue Mar  6 21:13:00 2012<br>
> @@ -27,3 +27,13 @@<br>
> }<br>
> s = { n }, // expected-warning {{non-constant-expression cannot be narrowed from type 'int' to 'char' in initializer list in C++11}} expected-note {{explicit cast}}<br>
> t = { 1234 }; // expected-warning {{constant expression evaluates to 1234 which cannot be narrowed to type 'char' in C++11}} expected-warning {{changes value}} expected-note {{explicit cast}}<br>
> +<br>
> +#define PRIuS "uS"<br>
> +int printf(const char *, ...);<br>
> +typedef __typeof(sizeof(int)) size_t;<br>
> +void h(size_t foo, size_t bar) {<br>
> +  printf("foo is %"PRIuS", bar is %"PRIuS, foo, bar); // expected-warning 2{{identifier after literal will be treated as a user-defined literal suffix in C++11}}<br>
> +}<br>
> +<br>
> +#define x + 1<br>
> +char c = 'x'x; // expected-warning {{will be treated as a user-defined literal suffix}}<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
<br>
</div></div></blockquote></div><br>