r265177 - Diagnose missing macro argument following charize operator.
Andy Gibbs via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 1 12:02:21 PDT 2016
Author: andyg
Date: Fri Apr 1 14:02:20 2016
New Revision: 265177
URL: http://llvm.org/viewvc/llvm-project?rev=265177&view=rev
Log:
Diagnose missing macro argument following charize operator.
For completeness, add a test-case for the equivalent stringize operator
diagnostic too.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
cfe/trunk/lib/Lex/PPDirectives.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.c
cfe/trunk/test/Preprocessor/stringize_misc.c
Modified: cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td?rev=265177&r1=265176&r2=265177&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticLexKinds.td Fri Apr 1 14:02:20 2016
@@ -387,7 +387,7 @@ def err_pp_expected_comma_in_arg_list :
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">;
Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=265177&r1=265176&r2=265177&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Fri Apr 1 14:02:20 2016
@@ -2151,7 +2151,7 @@ void Preprocessor::HandleDefineDirective
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
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);
Modified: cfe/trunk/test/Parser/MicrosoftExtensions.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.c?rev=265177&r1=265176&r2=265177&view=diff
==============================================================================
--- cfe/trunk/test/Parser/MicrosoftExtensions.c (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.c Fri Apr 1 14:02:20 2016
@@ -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 at -1 {{'#@' is not followed by a macro parameter}} */
typedef enum E { e1 };
Modified: cfe/trunk/test/Preprocessor/stringize_misc.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/stringize_misc.c?rev=265177&r1=265176&r2=265177&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/stringize_misc.c (original)
+++ cfe/trunk/test/Preprocessor/stringize_misc.c Fri Apr 1 14:02:20 2016
@@ -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
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 at -1{{'#' is not followed by a macro parameter}}
+
+#endif
More information about the cfe-commits
mailing list