Clang error: conditional expression is ambiguous; A and B can be converted to several common types (err_conditional_ambiguous_ovl)
Jump to navigation
Jump to search
Text |
| ||||||
---|---|---|---|---|---|---|---|
Type | Error | ||||||
Category | Semantic Issue | ||||||
Internal Id | err_conditional_ambiguous_ovl | ||||||
Internal Message | conditional expression is ambiguous; %diff{$ and $|types}0,1 can be converted to several common types
| ||||||
Regular Expression | (?:error|fatal error)\: conditional expression is ambiguous; (?:(.*?) and (.*?)|types) can be converted to several common types
| ||||||
First Commit | 2009-04-16 1a99f441e64c Fix a crash bug when comparing overload quality of conversion operators with conversion constructors... |
Description
Example
Flags | -xc++ -std=c++11
|
|
---|---|---|
Source |
struct A { operator int() { return 0; } operator double() { return 0.0; } };
struct B { operator int() { return 0; } operator double() { return 0.0; } };
int main() {
// A() and B() can both be converted to int or double
return true ? A() : B();
}
| |
Compiler Output |
<source>:6:15: error: conditional expression is ambiguous; 'A' and 'B' can be converted to several common types |
Clang Internals (17.0.6)
Git Commit Message
Fix a crash bug when comparing overload quality of conversion operators with conversion constructors. Remove an atrocious amount of trailing whitespace in the overloaded operator mangler. Sorry, couldn't help myself. Change the DeclType parameter of Sema::CheckReferenceInit to be passed by value instead of reference. It wasn't changed anywhere. Let the parser handle C++'s irregular grammar around assignment-expression and conditional-expression. And finally, the reason for all this stuff: implement C++ semantics for the conditional operator. The implementation is complete except for determining lvalueness. llvm-svn: 69299
Used in Clang Sources
This section lists all occurrences of the diagnostic within the Clang's codebase. For each occurrence, an auto-extracted snipped from the source code is listed including key elements like control structures, functions, or classes. It should illustrate the conditions under which the diagnostic is activated.
clang/lib/Sema/SemaExprCXX.cpp (line 6266)
/// Try to find a common type for two according to C++0x 5.16p5.
///
/// This is part of the parameter validation for the ? operator. If either
/// value operand is a class type, overload resolution is used to find a
/// conversion to a common type.
static bool FindConditionalOverload(Sema &Self, ExprResult &LHS, ExprResult &RHS, SourceLocation QuestionLoc) {
// ...
case OR_Ambiguous:
Self.Diag(QuestionLoc, diag::err_conditional_ambiguous_ovl) << LHS.get()->getType() << RHS.get()->getType() << LHS.get()->getSourceRange() << RHS.get()->getSourceRange();