-
-
Notifications
You must be signed in to change notification settings - Fork 262
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Hi,
this is a great tool for crosschecking the compiler's interpretation of C++ code. However the expansion of the ternary operator looks a bit misleading to me. Given the following code:
struct Str {
Str(const char* string) : string(string) {}
operator const char*() const {
return string;
}
const char* string;
};
Str globalString = "test";
const char* getString(bool empty) {
return empty ? "" : globalString;
}With C++17 the getString() function gets translated into:
const char * getString(bool empty)
{
return static_cast<const char *>(empty ? Str("") : Str(globalString).operator const char *());
}I would argue that a parenthesis is missing and it should look like this for both result types of the ternary expression to match:
const char * getString(bool empty)
{
return static_cast<const char *>((empty ? Str("") : Str(globalString)).operator const char *());
}Also when setting the compilation option to anything below C++17, then the result looks even weirder:
const char * getString(bool empty)
{
return static_cast<const char *>(empty ? Str(Str(Str(""))) : Str(globalString).operator const char *());
}Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working