]> granicus.if.org Git - clang/commitdiff
implement -Wmultichar
authorChris Lattner <sabre@nondot.org>
Tue, 28 Apr 2009 18:52:02 +0000 (18:52 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 28 Apr 2009 18:52:02 +0000 (18:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70315 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticLexKinds.td
lib/Lex/LiteralSupport.cpp
test/Lexer/constants.c

index 073b4a0cb2359efd3ffe5148d99b2be97fd51a80..c0afde52d3cb79fbb4c0a7d2c9abd32dbdc13305 100644 (file)
@@ -43,6 +43,7 @@ def : DiagGroup<"missing-braces">;
 def : DiagGroup<"missing-declarations">;
 def : DiagGroup<"missing-format-attribute">;
 def : DiagGroup<"missing-noreturn">;
+def MultiChar : DiagGroup<"multichar">;
 def : DiagGroup<"nested-externs">;
 def : DiagGroup<"newline-eof">;
 def : DiagGroup<"format-y2k">;
@@ -94,6 +95,7 @@ def : DiagGroup<"", [Extra]>;  // -W = -Wextra
 def Most : DiagGroup<"most", [
     Comment,
     Implicit,
+    MultiChar,
     Switch,
     Trigraphs,
     Uninitialized,
index b2e99df9deaad1d68a178c429c954d9b50c86ac9..471b13687323171ee3e7b3394311a643543298fb 100644 (file)
@@ -51,6 +51,8 @@ def err_empty_character : Error<"empty character constant">;
 def err_unterminated_block_comment : Error<"unterminated /* comment">;
 def err_invalid_character_to_charify : Error<
   "invalid argument to convert to character">;
+def ext_multichar_character_literal : ExtWarn<
+  "multi-character character constant">, InGroup<MultiChar>;
 
 // Literal
 def ext_nonstandard_escape : Extension<
index 03ecff91a57847a3633bfa6ed949cf38b882ec06..faa44b6fb0609927ec452a5d825202d14caa174e 100644 (file)
@@ -662,6 +662,8 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
         // constants (L'abcd').
         if (IsWide)
           PP.Diag(Loc, diag::warn_extraneous_wide_char_constant);
+        else
+          PP.Diag(Loc, diag::ext_multichar_character_literal);
       }
 
       if (IsWide) {
@@ -671,7 +673,6 @@ CharLiteralParser::CharLiteralParser(const char *begin, const char *end,
         // Narrow character literals act as though their value is concatenated
         // in this implementation.
         if ((LitVal.shl(8)).lshr(8) != LitVal)
-        // if (((LitVal << 8) >> 8) != LitVal)
           PP.Diag(Loc, diag::warn_char_constant_too_large);
         LitVal <<= 8;
       }
index c046581633672e3f4326aea59b62c03109212ed4..f5fc9e1493e64c4ce0663f5a8a70bb4b7e63446c 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: clang-cc -fsyntax-only -verify %s
+// RUN: clang-cc -fsyntax-only -verify -pedantic -trigraphs %s
 
 int x = 000000080;  // expected-error {{invalid digit}}
 
@@ -13,3 +13,17 @@ float Y = 08.123456;
 // PR2252
 #if -0x8000000000000000  // should not warn.
 #endif
+
+
+char c[] = {
+  'df',  // expected-warning {{multi-character character constant}}
+  '\t',
+  '\\
+t',
+  '??!'  // expected-warning {{trigraph converted to '|' character}}
+};
+
+
+#pragma GCC diagnostic ignored "-Wmultichar"
+
+char d = 'df'; // no warning.