r180701 - Fix an assertion failure / accepts-invalid in -fms-extensions mode. Don't build
Richard Smith
richard-llvm at metafoo.co.uk
Mon Apr 29 01:45:27 PDT 2013
Author: rsmith
Date: Mon Apr 29 03:45:27 2013
New Revision: 180701
URL: http://llvm.org/viewvc/llvm-project?rev=180701&view=rev
Log:
Fix an assertion failure / accepts-invalid in -fms-extensions mode. Don't build
a dependent-scope id expression when a templated member function of a
non-templated class references an unknown identifier, since instantiation won't
rebuild it (and we can tell at parse time that it'll never work). Based on a
patch by Faisal Vali!
Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp
Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=180701&r1=180700&r2=180701&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Mon Apr 29 03:45:27 2013
@@ -1916,15 +1916,17 @@ ExprResult Sema::ActOnIdExpression(Scope
// If this name wasn't predeclared and if this is not a function
// call, diagnose the problem.
if (R.empty()) {
-
// In Microsoft mode, if we are inside a template class member function
- // and we can't resolve an identifier then assume the identifier is type
- // dependent. The goal is to postpone name lookup to instantiation time
- // to be able to search into type dependent base classes.
- if (getLangOpts().MicrosoftMode && CurContext->isDependentContext() &&
- isa<CXXMethodDecl>(CurContext))
- return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
- IsAddressOfOperand, TemplateArgs);
+ // whose parent class has dependent base classes, and we can't resolve
+ // an identifier, then assume the identifier is type dependent. The
+ // goal is to postpone name lookup to instantiation time to be able to
+ // search into the type dependent base classes.
+ if (getLangOpts().MicrosoftMode) {
+ CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(CurContext);
+ if (MD && MD->getParent()->hasAnyDependentBases())
+ return ActOnDependentIdExpression(SS, TemplateKWLoc, NameInfo,
+ IsAddressOfOperand, TemplateArgs);
+ }
CorrectionCandidateCallback DefaultValidator;
if (DiagnoseEmptyLookup(S, SS, R, CCC ? *CCC : DefaultValidator))
Modified: cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp?rev=180701&r1=180700&r2=180701&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp (original)
+++ cfe/trunk/test/SemaTemplate/ms-lookup-template-base-classes.cpp Mon Apr 29 03:45:27 2013
@@ -8,7 +8,6 @@ public:
void g();// expected-note {{must qualify identifier to find this declaration in dependent base class}}
};
-
template <class T>
class B : public A<T> {
public:
@@ -28,6 +27,31 @@ void test()
b.z(3);
}
+struct A2 {
+ template<class T> void f(T) {
+ XX; //expected-error {{use of undeclared identifier 'XX'}}
+ A2::XX; //expected-error {{no member named 'XX' in 'A2'}}
+ }
+};
+template void A2::f(int);
+
+template<class T0>
+struct A3 {
+ template<class T1> void f(T1) {
+ XX; //expected-error {{use of undeclared identifier 'XX'}}
+ }
+};
+template void A3<int>::f(int);
+
+template<class T0>
+struct A4 {
+ void f(char) {
+ XX; //expected-error {{use of undeclared identifier 'XX'}}
+ }
+};
+template class A4<int>;
+
+
namespace lookup_dependent_bases_id_expr {
template<class T> class A {
More information about the cfe-commits
mailing list