LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 31816 - Clang-CL diagnoses ternary ambiguity which cl.exe allows
Summary: Clang-CL diagnoses ternary ambiguity which cl.exe allows
Status: NEW
Alias: None
Product: clang
Classification: Unclassified
Component: C++ (show other bugs)
Version: trunk
Hardware: PC Windows NT
: P normal
Assignee: Unassigned Clang Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-01-31 09:12 PST by Stephen Kelly
Modified: 2017-02-02 16:06 PST (History)
4 users (show)

See Also:
Fixed By Commit(s):


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Stephen Kelly 2017-01-31 09:12:53 PST
Given 


    struct MyBool
    {
        MyBool(bool b = false) {}
        operator bool() const { return false; }
    };

    int main()
    {
        MyBool mb;
        bool result = true ? false : mb;
        return 0;
    }


C:\dev\tmp>cl /c main.cpp
Microsoft (R) C/C++ Optimizing Compiler Version 19.00.24325.6 for x86
Copyright (C) Microsoft Corporation.  All rights reserved.

main.cpp

C:\dev\tmp>"c:\dev\src\llvm\build\Release\msbuild-bin\cl.exe" /c main.cpp
main.cpp(11,21):  error: conditional expression is ambiguous; 'bool' can be converted to 'MyBool' and vice versa
        bool result = true ? false : mb;
                           ^ ~~~~~   ~~
1 error generated.


It could be considered to match the behavior of cl.exe
Comment 1 Hans Wennborg 2017-02-02 16:06:43 PST
I'm not a language lawyer, but I suspect this example isn't valid C++.

If that's the case, and if it's not occurring in MS's headers (i.e. code that can't be fixed), I don't think we clang to change here.