[Bug c++/84906] New: [8 Regression] Ambiguous conversion not diagnosed, causes entire selection-statement to be omitted

redi at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Fri Mar 16 14:29:00 GMT 2018


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84906

            Bug ID: 84906
           Summary: [8 Regression] Ambiguous conversion not diagnosed,
                    causes entire selection-statement to be omitted
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid, wrong-code
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: redi at gcc dot gnu.org
  Target Milestone: ---

extern "C" int puts(const char*);

struct aa {
    operator auto() {
        puts("auto");
        return false;
    }
    explicit operator bool() {
        puts("bool");
        return true;
    }
};

int main() {
    aa x;
    if (x)
      puts("here");
    else
      puts("there");
}

This compiles and runs, but doesn't print anything (neither here not there, and
neither auto nor bool).

This seems to be a regression, as GCC 7 prints:

auto
there


Clang and EDG correctly diagnose it as ill-formed:


odd.cc:17:9: error: conversion from 'aa' to 'bool' is ambiguous
    if (x)
        ^
odd.cc:4:5: note: candidate function
    operator auto() {
    ^
odd.cc:8:14: note: candidate function
    explicit operator bool() {
             ^
1 error generated.



"odd.cc", line 17: error: more than one conversion function from "aa" to a
          built-in type applies:
            function "aa::operator bool()"
            function "aa::operator bool()"
      if (x)
          ^

1 error detected in the compilation of "odd.cc".


More information about the Gcc-bugs mailing list