]> granicus.if.org Git - clang/commitdiff
Diagnose missing macro argument following charize operator.
authorAndy Gibbs <andyg1001@hotmail.co.uk>
Fri, 1 Apr 2016 19:02:20 +0000 (19:02 +0000)
committerAndy Gibbs <andyg1001@hotmail.co.uk>
Fri, 1 Apr 2016 19:02:20 +0000 (19:02 +0000)
For completeness, add a test-case for the equivalent stringize operator
diagnostic too.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@265177 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticLexKinds.td
lib/Lex/PPDirectives.cpp
test/Parser/MicrosoftExtensions.c
test/Preprocessor/stringize_misc.c

index cd37bceedd98c993b92907aa6a1f0f2107066660..9df0967b44857cd049520e748d0bd1957ea302ab 100644 (file)
@@ -387,7 +387,7 @@ def err_pp_expected_comma_in_arg_list : Error<
 def err_pp_duplicate_name_in_arg_list : Error<
   "duplicate macro parameter name %0">;
 def err_pp_stringize_not_parameter : Error<
-  "'#' is not followed by a macro parameter">;
+  "'%select{#|#@}0' is not followed by a macro parameter">;
 def err_pp_malformed_ident : Error<"invalid #ident directive">;
 def err_pp_unterminated_conditional : Error<
   "unterminated conditional directive">;
index c36670ca635844a4d72b54de119049e0815737f5..dc1f32fb5697efe52256431610229f00ff840753 100644 (file)
@@ -2151,7 +2151,7 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok,
     while (Tok.isNot(tok::eod)) {
       LastTok = Tok;
 
-      if (Tok.isNot(tok::hash) && Tok.isNot(tok::hashhash)) {
+      if (!Tok.isOneOf(tok::hash, tok::hashat, tok::hashhash)) {
         MI->AddTokenToBody(Tok);
 
         // Get the next token of the macro.
@@ -2210,7 +2210,8 @@ void Preprocessor::HandleDefineDirective(Token &DefineTok,
           MI->AddTokenToBody(LastTok);
           continue;
         } else {
-          Diag(Tok, diag::err_pp_stringize_not_parameter);
+          Diag(Tok, diag::err_pp_stringize_not_parameter)
+            << LastTok.is(tok::hashat);
 
           // Disable __VA_ARGS__ again.
           Ident__VA_ARGS__->setIsPoisoned(true);
index e58a7455c083f3b4c125f423a67958ea1bb22980..39ab51f31fa67ef196730789fbea34e8258dba47 100644 (file)
@@ -35,6 +35,9 @@ void test_ms_alignof_alias(void) {
 /* Charify extension. */
 #define FOO(x) #@x
 char x = FOO(a);
+#define HASHAT #@
+#define MISSING_ARG(x) #@
+/* expected-error@-1 {{'#@' is not followed by a macro parameter}} */
 
 typedef enum E { e1 };
 
index 6c2c78d17ac3ad35d25f1dbdb3ae4a610bc6a6c2..fc7253e50499b41432d2d3157a81371da66cb4a4 100644 (file)
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -E %s | FileCheck -strict-whitespace %s
+#ifdef TEST1
+// RUN: %clang_cc1 -E %s -DTEST1 | FileCheck -strict-whitespace %s
 
 #define M(x, y) #x #y
 
@@ -28,3 +29,13 @@ START_END( {a=1 , b=2;} ) /* braces are not parentheses */
 M(a COMMA b, (a, b)) 
 // CHECK: "a COMMA b" "(a, b)"
 
+#endif
+
+#ifdef TEST2
+// RUN: %clang_cc1 -fsyntax-only -verify %s -DTEST2
+
+#define HASH #
+#define INVALID() #
+// expected-error@-1{{'#' is not followed by a macro parameter}}
+
+#endif