]> granicus.if.org Git - clang/commitdiff
When performing copy initialization via user-defined conversions,
authorDouglas Gregor <dgregor@apple.com>
Thu, 1 Jul 2010 03:43:00 +0000 (03:43 +0000)
committerDouglas Gregor <dgregor@apple.com>
Thu, 1 Jul 2010 03:43:00 +0000 (03:43 +0000)
don't allow two user-defined conversions. Fixes PR6595 (again).

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@107379 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaInit.cpp
test/SemaCXX/conditional-expr.cpp

index c2d6de749bf2a44981b13d59347380d104957d22..3acec5667094600a16e7e142ac17699bdbe98171 100644 (file)
@@ -2858,7 +2858,6 @@ static void TryUserDefinedConversion(Sema &S,
            Con != ConEnd; ++Con) {
         NamedDecl *D = *Con;
         DeclAccessPair FoundDecl = DeclAccessPair::make(D, D->getAccess());
-        bool SuppressUserConversions = false;
         
         // Find the constructor (which may be a template).
         CXXConstructorDecl *Constructor = 0;
@@ -2867,17 +2866,8 @@ static void TryUserDefinedConversion(Sema &S,
         if (ConstructorTmpl)
           Constructor = cast<CXXConstructorDecl>(
                                            ConstructorTmpl->getTemplatedDecl());
-        else {
+        else
           Constructor = cast<CXXConstructorDecl>(D);
-          
-          // If we're performing copy initialization using a copy constructor, 
-          // we suppress user-defined conversions on the arguments.
-          // FIXME: Move constructors?
-          if (Kind.getKind() == InitializationKind::IK_Copy &&
-              Constructor->isCopyConstructor())
-            SuppressUserConversions = true;
-          
-        }
         
         if (!Constructor->isInvalidDecl() &&
             Constructor->isConvertingConstructor(AllowExplicit)) {
@@ -2885,11 +2875,11 @@ static void TryUserDefinedConversion(Sema &S,
             S.AddTemplateOverloadCandidate(ConstructorTmpl, FoundDecl,
                                            /*ExplicitArgs*/ 0,
                                            &Initializer, 1, CandidateSet,
-                                           SuppressUserConversions);
+                                           /*SuppressUserConversions=*/true);
           else
             S.AddOverloadCandidate(Constructor, FoundDecl,
                                    &Initializer, 1, CandidateSet,
-                                   SuppressUserConversions);
+                                   /*SuppressUserConversions=*/true);
         }
       }    
     }
index a09ff2bd417d53f9b1e68403e2615271c57d430f..d008b8d6ed72728597304802dcf552b8ede4f558 100644 (file)
@@ -199,17 +199,24 @@ void test()
 }
 
 namespace PR6595 {
+  struct OtherString {
+    OtherString();
+    OtherString(const char*);
+  };
+
   struct String {
     String(const char *);
+    String(const OtherString&);
     operator const char*() const;
   };
 
-  void f(bool Cond, String S) {
+  void f(bool Cond, String S, OtherString OS) {
     (void)(Cond? S : "");
     (void)(Cond? "" : S);
     const char a[1] = {'a'};
     (void)(Cond? S : a);
     (void)(Cond? a : S);
+    (void)(Cond? OS : S);
   }
 }