summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Gibbs <andyg1001@hotmail.co.uk>2016-04-01 19:02:20 +0000
committerAndy Gibbs <andyg1001@hotmail.co.uk>2016-04-01 19:02:20 +0000
commitc49579d6eb3ecc3a4c3d0c23647a3fe8ca98701b (patch)
treedc9053f65842abb4aac99b5b3f9204bd4351ea47
parent882be36111f5d811e6719ae2147c9dd36a4fc1ae (diff)
Diagnose missing macro argument following charize operator.
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
-rw-r--r--include/clang/Basic/DiagnosticLexKinds.td2
-rw-r--r--lib/Lex/PPDirectives.cpp5
-rw-r--r--test/Parser/MicrosoftExtensions.c3
-rw-r--r--test/Preprocessor/stringize_misc.c13
4 files changed, 19 insertions, 4 deletions
diff --git a/include/clang/Basic/DiagnosticLexKinds.td b/include/clang/Basic/DiagnosticLexKinds.td
index cd37bceedd..9df0967b44 100644
--- a/include/clang/Basic/DiagnosticLexKinds.td
+++ b/include/clang/Basic/DiagnosticLexKinds.td
@@ -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">;
diff --git a/lib/Lex/PPDirectives.cpp b/lib/Lex/PPDirectives.cpp
index c36670ca63..dc1f32fb56 100644
--- a/lib/Lex/PPDirectives.cpp
+++ b/lib/Lex/PPDirectives.cpp
@@ -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);
diff --git a/test/Parser/MicrosoftExtensions.c b/test/Parser/MicrosoftExtensions.c
index e58a7455c0..39ab51f31f 100644
--- a/test/Parser/MicrosoftExtensions.c
+++ b/test/Parser/MicrosoftExtensions.c
@@ -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 };
diff --git a/test/Preprocessor/stringize_misc.c b/test/Preprocessor/stringize_misc.c
index 6c2c78d17a..fc7253e504 100644
--- a/test/Preprocessor/stringize_misc.c
+++ b/test/Preprocessor/stringize_misc.c
@@ -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