nomanous created this revision.
nomanous added a reviewer: rsmith.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
nomanous requested review of this revision.

The multi-character character constants should be implementation-defined 
according to the C standard but actually were made to be extension, which would 
cause errors when using clang with option "-pedantic-errors". This patch  fixes 
it and it is for bug #46797 on the Bugzilla system.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D87962

Files:
  clang/include/clang/Basic/DiagnosticLexKinds.td
  clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
  clang/test/FixIt/format.m
  clang/test/Lexer/multi-character-character-constant.c
  clang/test/Preprocessor/expr_multichar.c

Index: clang/test/Preprocessor/expr_multichar.c
===================================================================
--- clang/test/Preprocessor/expr_multichar.c
+++ clang/test/Preprocessor/expr_multichar.c
@@ -1,6 +1,6 @@
 // RUN: %clang_cc1 < %s -E -verify -triple i686-pc-linux-gnu
-// expected-no-diagnostics
+// Expect the warning of the four-character character constant after changing it from extension to implementation-defined
 
-#if (('1234' >> 24) != '1')
+#if (('1234' >> 24) != '1') // expected-warning {{multi-character character constant}}
 #error Bad multichar constant calculation!
 #endif
Index: clang/test/Lexer/multi-character-character-constant.c
===================================================================
--- /dev/null
+++ clang/test/Lexer/multi-character-character-constant.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -pedantic-errors %s
+
+int x = 'ab'; // expected-warning {{multi-character character constant}}
+int y = 'abcd'; // expected-warning {{multi-character character constant}}
+
+int main() {
+   return 0;
+}
+
Index: clang/test/FixIt/format.m
===================================================================
--- clang/test/FixIt/format.m
+++ clang/test/FixIt/format.m
@@ -161,14 +161,17 @@
   // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%c"
 
 
-  NSLog(@"%s", 'abcd'); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+  NSLog(@"%s", 'abcd'); // expected-warning{{format specifies type 'char *' but the argument has type 'int'}} \
+  // expected-warning {{multi-character character constant}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%d"
 
-  NSLog(@"%lf", 'abcd'); // expected-warning{{format specifies type 'double' but the argument has type 'int'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:14}:"%d"
+  NSLog(@"%lf", 'abcd'); // expected-warning{{format specifies type 'double' but the argument has type 'int'}} \
+  // expected-warning {{multi-character character constant}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:14}:"%d"
 
-  NSLog(@"%@", 'abcd'); // expected-warning{{format specifies type 'id' but the argument has type 'int'}}
-  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+  NSLog(@"%@", 'abcd'); // expected-warning{{format specifies type 'id' but the argument has type 'int'}} \
+  // expected-warning {{multi-character character constant}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%d"
 }
 
 void multichar_constants_false_negative() {
@@ -177,8 +180,9 @@
   // type-checker expects %c to correspond to an integer argument, because
   // many C library functions like fgetc() actually return an int (using -1
   // as a sentinel).
-  NSLog(@"%c", 'abcd'); // missing-warning{{format specifies type 'char' but the argument has type 'int'}}
-  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:13}:"%d"
+  NSLog(@"%c", 'abcd'); // missing-warning{{format specifies type 'char' but the argument has type 'int'}} \
+  // expected-warning {{multi-character character constant}}
+  // CHECK-NOT: fix-it:"{{.*}}":{[[@LINE-2]]:11-[[@LINE-2]]:13}:"%d"
 }
 
 
Index: clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
===================================================================
--- clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
+++ clang/test/CXX/lex/lex.literal/lex.ccon/p1.cpp
@@ -1,12 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
+// Expect the warning of the four-character character constant after changing it from extension to implementation-defined
 
 // Check types of char literals
 extern char a;
 extern __typeof('a') a;
 extern int b;
-extern __typeof('asdf') b;
+extern __typeof('asdf') b; // expected-warning {{multi-character character constant}}
 extern wchar_t c;
 extern __typeof(L'a') c;
 #if __cplusplus >= 201103L
Index: clang/include/clang/Basic/DiagnosticLexKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticLexKinds.td
+++ clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -104,9 +104,9 @@
   "raw string literals are incompatible with C++98">,
   InGroup<CXX98Compat>, DefaultIgnore;
 
-def ext_multichar_character_literal : ExtWarn<
+def ext_multichar_character_literal : Warning<
   "multi-character character constant">, InGroup<MultiChar>;
-def ext_four_char_character_literal : Extension<
+def ext_four_char_character_literal : Warning<
   "multi-character character constant">, InGroup<FourByteMultiChar>;
 
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to