diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-12-01 16:58:18 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-12-01 16:58:18 +0000 |
commit | e7488b904ca95dc3f41bfed979c77cfe00f037ae (patch) | |
tree | e4ec47c5ccc5d24939b0e7fa7a8d7cfaa41796e8 /clang/lib/Sema/SemaExpr.cpp | |
parent | f107aa63eeae5385ad4fd22074b7f011cac7eb1c (diff) | |
download | bcm5719-llvm-e7488b904ca95dc3f41bfed979c77cfe00f037ae.tar.gz bcm5719-llvm-e7488b904ca95dc3f41bfed979c77cfe00f037ae.zip |
Don't automatically assume that an id-expression refers to a
ValueDecl, because that isn't always the case in ill-formed
code. Diagnose a common mistake (forgetting to provide a template
argument list for a class template, PR5655) and dyn_cast so that we
handle the general problem of referring to a non-value declaration
gracefully.
llvm-svn: 90239
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index f653cf63d80..bf14d0d3032 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1246,7 +1246,23 @@ Sema::BuildDeclarationNameExpr(const CXXScopeSpec &SS, if (CheckDeclInExpr(*this, Loc, D)) return ExprError(); - ValueDecl *VD = cast<ValueDecl>(D); + if (TemplateDecl *Template = dyn_cast<TemplateDecl>(D)) { + // Specifically diagnose references to class templates that are missing + // a template argument list. + Diag(Loc, diag::err_template_decl_ref) + << Template << SS.getRange(); + Diag(Template->getLocation(), diag::note_template_decl_here); + return ExprError(); + } + + // Make sure that we're referring to a value. + ValueDecl *VD = dyn_cast<ValueDecl>(D); + if (!VD) { + Diag(Loc, diag::err_ref_non_value) + << D << SS.getRange(); + Diag(D->getLocation(), diag::note_previous_decl); + return ExprError(); + } // Check whether this declaration can be used. Note that we suppress // this check when we're going to perform argument-dependent lookup |