Refactored duplicate string literal lexing code within Preprocessor, into a
common LexStringLiteral function. In doing so, some consistency problems have
been ironed out (e.g. where the first token in the string literal was lexed
with macro expansion, but subsequent ones were not) and also an erroneous
diagnostic has been corrected.
LexStringLiteral is complemented by a FinishLexStringLiteral function which
can be used in the situation where the first token of the string literal has
already been lexed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@168266 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/Preprocessor/warning_tests.c b/test/Preprocessor/warning_tests.c
index ac0b37b..77b8456 100644
--- a/test/Preprocessor/warning_tests.c
+++ b/test/Preprocessor/warning_tests.c
@@ -11,7 +11,7 @@
#warning Should have -Wparentheses
#endif
-// expected-error@+2 {{builtin warning check macro requires a parenthesized string}}
+// expected-error@+2 {{expected string literal}}
// expected-error@+1 {{expected value in expression}}
#if __has_warning(-Wfoo)
#endif
@@ -21,3 +21,26 @@
#else
#warning Not a valid warning flag
#endif
+
+// expected-error@+2 {{builtin warning check macro requires a parenthesized string}}
+// expected-error@+1 {{invalid token}}
+#if __has_warning "not valid"
+#endif
+
+// Macro expansion does not occur in the parameter to __has_warning
+// (as is also expected behaviour for ordinary macros), so the
+// following should not expand:
+
+#define MY_ALIAS "-Wparentheses"
+
+// expected-error@+1 2{{expected}}
+#if __has_warning(MY_ALIAS)
+#error Alias expansion not allowed
+#endif
+
+// But deferring should expand:
+#define HAS_WARNING(X) __has_warning(X)
+
+#if !HAS_WARNING(MY_ALIAS)
+#error Expansion should have occurred
+#endif