[cfe-dev] Guaranteed copy elision and GNU ?: operator
John McCall via cfe-dev
cfe-dev at lists.llvm.org
Thu Oct 26 01:31:17 PDT 2017
> On Oct 25, 2017, at 8:47 PM, Hal Finkel via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> On 10/25/2017 07:42 PM, Ronald Wampler wrote:
>> On Wed, Oct 25, 2017 at 7:35 PM, Hal Finkel <hfinkel at anl.gov> wrote:
>>> On 10/25/2017 02:54 PM, Ronald Wampler wrote:
>>>> On Wed, Oct 25, 2017 at 2:09 PM, Hal Finkel <hfinkel at anl.gov> wrote:
>>>> It prints 42 when compiled with c++14 and 0 with c++17 (c++1z).
>>>> I also submitted this with a simpler case as
>>> To ask the obvious question, given that this is a GNU extension, has this
>>> been raised with the GCC developers? I imagine that we do want to match
>>> GCC's behavior in this regard.
>> Argh! This is embarrassing. I'm on a Mac and when I installed gcc I forgot
>> that `g++` is sym-linked to clang.
>> It appears that gcc never allowed this code to compile to begin with. See
>> godbolt: https://godbolt.org/g/8DdytF
>> So I guess clang should give an error here too.
> Ah, okay. Please update your bug report as well.
There are several GCC extensions that we intentionally support in C++ mode even when GCC does not, and IIRC ?: is one of them.
We cannot perform any sort of copy/move elision on the result of ?: because of the rules around the order of destruction of temporaries. We can of course at least attempt to move it. It is likely that there is some piece of code which fails to understand this correctly in C++17 mode.
>>> Hal Finkel
>>> Lead, Compiler Technology and Programming Languages
>>> Leadership Computing Facility
>>> Argonne National Laboratory
> Hal Finkel
> Lead, Compiler Technology and Programming Languages
> Leadership Computing Facility
> Argonne National Laboratory
> cfe-dev mailing list
> cfe-dev at lists.llvm.org <mailto:cfe-dev at lists.llvm.org>
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev <http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev