[cfe-commits] r131811 - in /cfe/trunk: lib/AST/ASTContext.cpp lib/Sema/SemaTemplateDeduction.cpp lib/Sema/SemaType.cpp test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp test/SemaTemplate/deduction-crash.cpp

Douglas Gregor dgregor at apple.com
Sat May 21 15:16:51 PDT 2011


Author: dgregor
Date: Sat May 21 17:16:50 2011
New Revision: 131811

URL: http://llvm.org/viewvc/llvm-project?rev=131811&view=rev
Log:
It's considered poor form to create references to the overloaded
function type. Educate template argument deduction thusly, fixing
PR9974 / <rdar://problem/9479155>.

Modified:
    cfe/trunk/lib/AST/ASTContext.cpp
    cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
    cfe/trunk/lib/Sema/SemaType.cpp
    cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
    cfe/trunk/test/SemaTemplate/deduction-crash.cpp

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=131811&r1=131810&r2=131811&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Sat May 21 17:16:50 2011
@@ -1423,6 +1423,9 @@
 /// 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;

Modified: cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp?rev=131811&r1=131810&r2=131811&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp Sat May 21 17:16:50 2011
@@ -2507,7 +2507,9 @@
     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);
     }
 

Modified: cfe/trunk/lib/Sema/SemaType.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaType.cpp?rev=131811&r1=131810&r2=131811&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaType.cpp (original)
+++ cfe/trunk/lib/Sema/SemaType.cpp Sat May 21 17:16:50 2011
@@ -1071,6 +1071,9 @@
 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 

Modified: cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp?rev=131811&r1=131810&r2=131811&view=diff
==============================================================================
--- cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp (original)
+++ cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp Sat May 21 17:16:50 2011
@@ -33,8 +33,8 @@
   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 @@
   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()) {
   }

Modified: cfe/trunk/test/SemaTemplate/deduction-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/deduction-crash.cpp?rev=131811&r1=131810&r2=131811&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/deduction-crash.cpp (original)
+++ cfe/trunk/test/SemaTemplate/deduction-crash.cpp Sat May 21 17:16:50 2011
@@ -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 @@
   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>;
+}





More information about the cfe-commits mailing list