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

--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
(In reply to Simon Richter from comment #0)
> 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.

It's also accepted by Clang and Intel icc.

> 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

Which extension is that?

> will also pass array types through ternaries if
> they are both the same.

The C++ standard says it should be an lvalue:
https://en.cppreference.com/w/cpp/language/operator_other#Conditional_operator


>  - Is this intentional?
>  - Will it remain supported?

Yes, it's the behaviour required by the standard.

>  - Can it be turned off somehow?

Reply via email to