From: Douglas Gregor Date: Fri, 15 Oct 2010 00:50:56 +0000 (+0000) Subject: Add builtin conditional operator candidates for scoped enumeration X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=5a1f97ee183d2614db58452a4380dd11cb309263;p=clang Add builtin conditional operator candidates for scoped enumeration types, from Alp Toker! Fixes PR8344. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116549 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 4fef397f37..d2f6ee725d 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -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()->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 index 0000000000..c185fb4fb9 --- /dev/null +++ b/test/CXX/over/over.built/p25.cpp @@ -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; +}