[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#859116: GCC miscompiles following code, unlike clang



On Thu, Mar 30, 2017 at 04:23:41PM +0300, Roman Lebedev wrote:
> Package: g++-6
> Version: 6.3.0-11
> Severity: normal
> Tags: upstream
> 
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA512
> 
> Hi.
> 
> Yes, this issue should be sent upstream. But i'm unable to do that
> because their bugzilla does not want to reset my password.
> 
> The attached testcase was minimized.
> With gcc (6), the exit code is 10.
> With clang (tried with current svn version), the exit code is 0.
> As it should be pretty clear from the code, 0 is the correct answer.

No, it is unspecified.

[snipped all the info]
> 
> *** buffer.cpp
> struct a {
>   int b;
>   int c = 0;
>   a(int d) : b(d) {}
>   int e() { return b - c; }
>   void *f(int d) {
>     c = d;
>     return 0;
>   }
> };
> int g(void *, int h) { return h; }
> a i(10);
> int j = i.e();
> int main() { return g(i.f(j), i.e()); }

So, which one of i.f(j) and i.e() will be called first in the return
statement?

This is unspecified, there are no sequence points between the two.

It may even depend on the compiler options (optimization level).

In other words, this is not a bug.

    Gabriel


Reply to: