[cfe-commits] r74472 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/Sema.h lib/Sema/SemaTemplateInstantiate.cpp lib/Sema/SemaType.cpp test/SemaCXX/decltype-overloaded-functions.cpp
Anders Carlsson
andersca at mac.com
Mon Jun 29 15:58:56 PDT 2009
Author: andersca
Date: Mon Jun 29 17:58:55 2009
New Revision: 74472
URL: http://llvm.org/viewvc/llvm-project?rev=74472&view=rev
Log:
Improvements to decltype. We now don't crash anymore when the expr is an overloaded function decl.
Added:
cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaType.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=74472&r1=74471&r2=74472&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Mon Jun 29 17:58:55 2009
@@ -398,6 +398,10 @@
def note_uninit_reference_member : Note<
"uninitialized reference member is here">;
+// C++0x decltype
+def err_cannot_determine_declared_type_of_overloaded_function : Error<
+ "can't determine the declared type of an overloaded function">;
+
// C++0x auto
def err_auto_variable_cannot_appear_in_own_initializer : Error<
"variable %0 declared with 'auto' type cannot appear in its own initializer">;
Modified: cfe/trunk/lib/Sema/Sema.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/Sema.h?rev=74472&r1=74471&r2=74472&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/Sema.h (original)
+++ cfe/trunk/lib/Sema/Sema.h Mon Jun 29 17:58:55 2009
@@ -406,6 +406,9 @@
QualType getQualifiedNameType(const CXXScopeSpec &SS, QualType T);
+ QualType BuildTypeofExprType(Expr *E);
+ QualType BuildDecltypeType(Expr *E);
+
//===--------------------------------------------------------------------===//
// Symbol table / Decl tracking callbacks: SemaDecl.cpp.
//
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp?rev=74472&r1=74471&r2=74472&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp Mon Jun 29 17:58:55 2009
@@ -530,7 +530,7 @@
if (E.isInvalid())
return QualType();
- return SemaRef.Context.getTypeOfExprType(E.takeAs<Expr>());
+ return SemaRef.BuildTypeofExprType(E.takeAs<Expr>());
}
QualType
@@ -555,7 +555,7 @@
if (E.isInvalid())
return QualType();
- return SemaRef.Context.getDecltypeType(E.takeAs<Expr>());
+ return SemaRef.BuildDecltypeType(E.takeAs<Expr>());
}
QualType
Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=74472&r1=74471&r2=74472&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Mon Jun 29 17:58:55 2009
@@ -242,7 +242,11 @@
Expr *E = static_cast<Expr *>(DS.getTypeRep());
assert(E && "Didn't get an expression for decltype?");
// TypeQuals handled by caller.
- Result = Context.getDecltypeType(E);
+ Result = BuildDecltypeType(E);
+ if (Result.isNull()) {
+ Result = Context.IntTy;
+ isInvalid = true;
+ }
break;
}
case DeclSpec::TST_auto: {
@@ -1463,3 +1467,16 @@
= static_cast<NestedNameSpecifier *>(SS.getScopeRep());
return Context.getQualifiedNameType(NNS, T);
}
+
+QualType Sema::BuildTypeofExprType(Expr *E) {
+ return Context.getTypeOfExprType(E);
+}
+
+QualType Sema::BuildDecltypeType(Expr *E) {
+ if (E->getType() == Context.OverloadTy) {
+ Diag(E->getLocStart(),
+ diag::err_cannot_determine_declared_type_of_overloaded_function);
+ return QualType();
+ }
+ return Context.getDecltypeType(E);
+}
Added: cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp?rev=74472&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp (added)
+++ cfe/trunk/test/SemaCXX/decltype-overloaded-functions.cpp Mon Jun 29 17:58:55 2009
@@ -0,0 +1,12 @@
+// RUN: clang-cc -fsyntax-only -verify %s -std=c++0x
+
+void f();
+void f(int);
+decltype(f) a; // expected-error{{can't determine the declared type of an overloaded function}}
+
+template<typename T> struct S {
+ decltype(T::f) * f; // expected-error{{can't determine the declared type of an overloaded function}}
+};
+
+struct K { void f(); void f(int); };
+S<K> b; // expected-note{{in instantiation of template class 'struct S<struct K>' requested here}}
More information about the cfe-commits
mailing list