diff options
author | Douglas Gregor <dgregor@apple.com> | 2011-05-21 22:16:50 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2011-05-21 22:16:50 +0000 |
commit | 291e8ee20687e397ce315a6ab72e5671bc03227d (patch) | |
tree | 31d53836d52657d7e65be98c95d9eef9d7523612 | |
parent | b7c36f6c681f22c413b5e27d1aeeeaff80889f76 (diff) | |
download | bcm5719-llvm-291e8ee20687e397ce315a6ab72e5671bc03227d.tar.gz bcm5719-llvm-291e8ee20687e397ce315a6ab72e5671bc03227d.zip |
It's considered poor form to create references to the overloaded
function type. Educate template argument deduction thusly, fixing
PR9974 / <rdar://problem/9479155>.
llvm-svn: 131811
-rw-r--r-- | clang/lib/AST/ASTContext.cpp | 3 | ||||
-rw-r--r-- | clang/lib/Sema/SemaTemplateDeduction.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Sema/SemaType.cpp | 3 | ||||
-rw-r--r-- | clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp | 6 | ||||
-rw-r--r-- | clang/test/SemaTemplate/deduction-crash.cpp | 36 |
5 files changed, 45 insertions, 7 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index b0303797e41..e664855067f 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -1423,6 +1423,9 @@ QualType ASTContext::getBlockPointerType(QualType T) const { /// lvalue reference to the specified type. QualType ASTContext::getLValueReferenceType(QualType T, bool SpelledAsLValue) const { + assert(getCanonicalType(T) != OverloadTy && + "Unresolved overloaded function type"); + // Unique pointers, to guarantee there is only one pointer of a particular // structure. llvm::FoldingSetNodeID ID; diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 235af049cf8..f2ec09b132c 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -2507,7 +2507,9 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(Sema &S, if (isa<RValueReferenceType>(ParamType)) { if (!PointeeType.getQualifiers() && isa<TemplateTypeParmType>(PointeeType) && - Arg->Classify(S.Context).isLValue()) + Arg->Classify(S.Context).isLValue() && + Arg->getType() != S.Context.OverloadTy && + Arg->getType() != S.Context.BoundMemberTy) ArgType = S.Context.getLValueReferenceType(ArgType); } diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp index dbacb47812a..884144f99b4 100644 --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -1071,6 +1071,9 @@ QualType Sema::BuildPointerType(QualType T, QualType Sema::BuildReferenceType(QualType T, bool SpelledAsLValue, SourceLocation Loc, DeclarationName Entity) { + assert(Context.getCanonicalType(T) != Context.OverloadTy && + "Unresolved overloaded function type"); + // C++0x [dcl.ref]p6: // If a typedef (7.1.3), a type template-parameter (14.3.1), or a // decltype-specifier (7.1.6.2) denotes a type TR that is a reference to a diff --git a/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp b/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp index 12acde143c4..7bfa6fe5826 100644 --- a/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp +++ b/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp @@ -33,8 +33,8 @@ struct B { int *alt_end(); }; -void f(); // expected-note {{candidate}} -void f(int); // expected-note {{candidate}} +void f(); +void f(int); void g() { for (int a : A()) @@ -44,7 +44,7 @@ void g() { for (char *a : B()) { // expected-error {{cannot initialize a variable of type 'char *' with an lvalue of type 'int'}} } // FIXME: Terrible diagnostic here. auto deduction should fail, but does not! - for (double a : f) { // expected-error {{address of overloaded function 'f' does not match required type '<overloaded function type>'}} + for (double a : f) { // expected-error {{cannot use type '<overloaded function type>' as a range}} } for (auto a : A()) { } diff --git a/clang/test/SemaTemplate/deduction-crash.cpp b/clang/test/SemaTemplate/deduction-crash.cpp index ec97311e5d7..fb23eda5bb9 100644 --- a/clang/test/SemaTemplate/deduction-crash.cpp +++ b/clang/test/SemaTemplate/deduction-crash.cpp @@ -1,10 +1,10 @@ // RUN: %clang_cc1 -fsyntax-only %s 2>&1| FileCheck %s -// PR7511 - // Note that the error count below doesn't matter. We just want to // make sure that the parser doesn't crash. -// CHECK: 13 errors +// CHECK: 14 errors + +// PR7511 template<a> struct int_; @@ -57,3 +57,33 @@ int a() state_machine<int> p; p.ant(0); } + +// PR9974 +template <int> struct enable_if; +template <class > struct remove_reference ; +template <class _Tp> struct remove_reference<_Tp&> ; + +template <class > struct __tuple_like; + +template <class _Tp, class _Up, int = __tuple_like<typename remove_reference<_Tp>::type>::value> +struct __tuple_convertible; + +struct pair +{ +template<class _Tuple, int = enable_if<__tuple_convertible<_Tuple, pair>::value>::type> +pair(_Tuple&& ); +}; + +template <class> struct basic_ostream; + +template <int> +void endl( ) ; + +extern basic_ostream<char> cout; + +int operator<<( basic_ostream<char> , pair ) ; + +void register_object_imp ( ) +{ +cout << endl<1>; +} |