aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Lex/Preprocessor.cpp7
-rw-r--r--Sema/SemaDecl.cpp3
-rw-r--r--test/Preprocessor/undef-error.c5
3 files changed, 11 insertions, 4 deletions
diff --git a/Lex/Preprocessor.cpp b/Lex/Preprocessor.cpp
index a291fe35df..7bd359ae18 100644
--- a/Lex/Preprocessor.cpp
+++ b/Lex/Preprocessor.cpp
@@ -1498,11 +1498,14 @@ void Preprocessor::ReadMacroName(Token &MacroNameTok, char isDefineUndef) {
/// not, emit a diagnostic and consume up until the eom.
void Preprocessor::CheckEndOfDirective(const char *DirType) {
Token Tmp;
- Lex(Tmp);
+ // Lex unexpanded tokens: macros might expand to zero tokens, causing us to
+ // miss diagnosing invalid lines.
+ LexUnexpandedToken(Tmp);
+
// There should be no tokens after the directive, but we allow them as an
// extension.
while (Tmp.is(tok::comment)) // Skip comments in -C mode.
- Lex(Tmp);
+ LexUnexpandedToken(Tmp);
if (Tmp.isNot(tok::eom)) {
Diag(Tmp, diag::ext_pp_extra_tokens_at_eol, DirType);
diff --git a/Sema/SemaDecl.cpp b/Sema/SemaDecl.cpp
index 2f866c0497..61de36faf6 100644
--- a/Sema/SemaDecl.cpp
+++ b/Sema/SemaDecl.cpp
@@ -1032,8 +1032,7 @@ Sema::DeclTy *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Declarator &D) {
}
}
Decl *decl = static_cast<Decl*>(ActOnDeclarator(GlobalScope, D, 0));
- FunctionDecl *FD = dyn_cast<FunctionDecl>(decl);
- assert(FD != 0 && "ActOnDeclarator() didn't return a FunctionDecl");
+ FunctionDecl *FD = cast<FunctionDecl>(decl);
CurFunctionDecl = FD;
// Create Decl objects for each parameter, adding them to the FunctionDecl.
diff --git a/test/Preprocessor/undef-error.c b/test/Preprocessor/undef-error.c
new file mode 100644
index 0000000000..af9f516f11
--- /dev/null
+++ b/test/Preprocessor/undef-error.c
@@ -0,0 +1,5 @@
+// RUN: not clang %s -pedantic-errors -E
+// PR2045
+
+#define b
+#undef a b