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

            Bug ID: 86351
           Summary: Array references as arguments to ternary operator
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Simon.Richter at hogyros dot de
  Target Milestone: ---

The code

    char const array1[2] = { 'a', 'b' };
    char const array2[2] = { 'c', 'd' };

    char foo(bool b) {
        char const (&bar)[2] = b ? array1 : array2;
        return bar[1];
    }

is accepted by g++ and rejected by MSVC.

My interpretation of the standard would be that MSVC is correct here, as the
array decays into a pointer in the ternary operator, but it seems gcc's
ternary-as-lvalue extension will also pass array types through ternaries if
they are both the same.

 - Is this intentional?
 - Will it remain supported?
 - Can it be turned off somehow?

Reply via email to