]> granicus.if.org Git - clang/commitdiff
Add builtin conditional operator candidates for scoped enumeration
authorDouglas Gregor <dgregor@apple.com>
Fri, 15 Oct 2010 00:50:56 +0000 (00:50 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 15 Oct 2010 00:50:56 +0000 (00:50 +0000)
types, from Alp Toker! Fixes PR8344.

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

lib/Sema/SemaOverload.cpp
test/CXX/over/over.built/p25.cpp [new file with mode: 0644]

index 4fef397f37a80d3f5170c8516d95da1742e6f5e3..d2f6ee725d5120041b16eadff778d53432d7dc08 100644 (file)
@@ -5255,9 +5255,9 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
     // contextually converted to bool long ago. The candidates below are
     // therefore added as binary.
     //
-    // C++ [over.built]p24:
-    //   For every type T, where T is a pointer or pointer-to-member type,
-    //   there exist candidate operator functions of the form
+    // C++ [over.built]p25:
+    //   For every type T, where T is a pointer, pointer-to-member, or scoped
+    //   enumeration type, there exist candidate operator functions of the form
     //
     //        T        operator?(bool, T, T);
     //
@@ -5272,6 +5272,15 @@ Sema::AddBuiltinOperatorCandidates(OverloadedOperatorKind Op,
       QualType ParamTypes[2] = { *Ptr, *Ptr };
       AddBuiltinCandidate(*Ptr, ParamTypes, Args, 2, CandidateSet);
     }
+    if (getLangOptions().CPlusPlus0x)
+    for (BuiltinCandidateTypeSet::iterator Enum =
+         CandidateTypes.enumeration_begin(),
+         E = CandidateTypes.enumeration_end(); Enum != E; ++Enum) {
+      if (!(*Enum)->getAs<EnumType>()->getDecl()->isScoped())
+        continue;
+      QualType ParamTypes[2] = { *Enum, *Enum };
+      AddBuiltinCandidate(*Enum, ParamTypes, Args, 2, CandidateSet);
+    }
     goto Conditional;
   }
 }
diff --git a/test/CXX/over/over.built/p25.cpp b/test/CXX/over/over.built/p25.cpp
new file mode 100644 (file)
index 0000000..c185fb4
--- /dev/null
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++0x %s
+
+enum class Color { Red, Green, Blue };
+
+struct ConvertsToColorA {
+  operator Color();
+};
+
+struct ConvertsToColorB {
+  operator Color();
+};
+
+Color foo(bool cond, ConvertsToColorA ca, ConvertsToColorB cb) {
+  return cond? ca : cb;
+}