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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@90239
91177308-0d34-0410-b5e6-
96231b3b80d8
"of type %1">;
def note_field_decl : Note<"member is declared here">;
-def note_previous_class_decl : Note<
+def note_previous_decl : Note<
"%0 declared here">;
def note_member_synthesized_at : Note<
"implicit default %select{constructor|copy constructor|"
"extraneous 'template<>' in declaration of variable %0">;
def err_template_tag_noparams : Error<
"extraneous 'template<>' in declaration of %0 %1">;
+def err_template_decl_ref : Error<
+ "cannot refer to class template %0 without a template argument list">;
// C++ Template Argument Lists
def err_template_arg_list_different_arity : Error<
def err_unexpected_interface : Error<
"unexpected interface name %0: expected expression">;
+def err_ref_non_value : Error<"%0 does not refer to a value">;
def err_property_not_found : Error<
"property %0 not found on object of type %1">;
def ext_gnu_void_ptr : Extension<
// C++0x CWG Issue #817 indicates that [[final]] classes shouldn't be bases.
if (CXXBaseDecl->hasAttr<FinalAttr>()) {
Diag(BaseLoc, diag::err_final_base) << BaseType.getAsString();
- Diag(CXXBaseDecl->getLocation(), diag::note_previous_class_decl)
- << BaseType.getAsString();
+ Diag(CXXBaseDecl->getLocation(), diag::note_previous_decl)
+ << BaseType;
return 0;
}
Diag(Constructor->getLocation(), diag::err_missing_default_ctor)
<< (int)IsImplicitConstructor << Context.getTagDeclType(ClassDecl)
<< 0 << VBase->getType();
- Diag(VBaseDecl->getLocation(), diag::note_previous_class_decl)
+ Diag(VBaseDecl->getLocation(), diag::note_previous_decl)
<< Context.getTagDeclType(VBaseDecl);
HadError = true;
continue;
Diag(Constructor->getLocation(), diag::err_missing_default_ctor)
<< (int)IsImplicitConstructor << Context.getTagDeclType(ClassDecl)
<< 0 << Base->getType();
- Diag(BaseDecl->getLocation(), diag::note_previous_class_decl)
+ Diag(BaseDecl->getLocation(), diag::note_previous_decl)
<< Context.getTagDeclType(BaseDecl);
HadError = true;
continue;
<< (int)IsImplicitConstructor << Context.getTagDeclType(ClassDecl)
<< 1 << (*Field)->getDeclName();
Diag(Field->getLocation(), diag::note_field_decl);
- Diag(RT->getDecl()->getLocation(), diag::note_previous_class_decl)
+ Diag(RT->getDecl()->getLocation(), diag::note_previous_decl)
<< Context.getTagDeclType(RT->getDecl());
HadError = true;
continue;
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
int final_fail [[final]]; //expected-error {{'final' attribute only applies to virtual method or class types}}
-struct [[final]] final_base { }; // expected-note {{struct final_base declared here}}
+struct [[final]] final_base { }; // expected-note {{'struct final_base' declared here}}
struct final_child : final_base { }; // expected-error {{derivation from 'final' struct final_base}}
struct final_member { virtual void quux [[final]] (); }; // expected-note {{overridden virtual function is here}}
};
struct [[base_check, base_check]] bc : base { // expected-error {{'base_check' attribute cannot be repeated}}
-};
\ No newline at end of file
+};
N::C<int> c1;
typedef N::C<float> c2;
+
+// PR5655
+template<typename T> struct Foo { }; // expected-note{{template is declared here}}
+
+void f(void) { Foo bar; } // expected-error{{without a template argument list}}