g++ 5.4.0 inserting const cast that breaks a constexpr - diagnostics ?

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

 



Hi -
I have some code that is compiled with no warnings / errors
by g++ 7.1.0 with '-std=gnu++14' , but under g++ 5.4.0 there
is a constexpr function which g++ 5.4.0 is convinced involves
a const cast, but g++ 7.1.0 accepts does not :

 'in constexpr expansion of x->f((T)v...))
 X.h:134:39: error: '*(const X*)this' is not a constant expression
( I did not write ((T)v) either ...)
but there is NO cast expression anywhere in the file , certainly no
text '(const X*)this' or ((T)v) - this is some compiler generated temporary,
that g++ 5.4.0 is generating, but g++ 7.1.0 does not ;  on the line
in question, I am calling a 'constexpr bool f(...) const noexcept' member
function of a const X *:
            class X { ... constexpr bool f(..) const noexcept { .. } };
            constexpr bool y(const X* x){ ...
    134:         if ( x->f( ... ) ) ...
            }

I would like to be able to compile my constexpr functions under
either g++ 4.9+ or g++ 6+ or g++ 7+ .  So far, 7.1.0 is getting it right
(I had to remove 6.3.0 - will rebuild later) .

What did 7.1.0  fix in regards to constexprs / temporary generation   ?

Is there any way to get G++ 5.4.0 to print out WHY it thinks  a function is not
constexpr ?
ANY compiler debug output / intermediate form that shows the compiler's
thinking or the exact line that is generating the temporary would be
invaluable here, but I can't seem to find any way of generating it  .
But I think attempting to generate eg. a GIMP intermediate
file would not show the error since compilation would not get to that stage ?
Is there a preliminary C++ parsing stage / debug mode whose output would show
what is requiring the generation of the temporary ? Before I start trying to
debug g++ with gdb , I thought I'd better ask .

The actual X::f() function is just doing a test on some integer arguments in a
conditional expression and returning a boolean - I just cannot see how it
can possibly involve a (const X*)  cast, since it is declared 'bool
f(...) CONST ...' -
obviously 5.4.0 is getting it wrong somehow, but 7.1.0 gets it right - if anyone
with detailed knowledge of what constexpr issues were fixed in 7.1.0 could
point me towards a few possible causes I might be able to figure out a
workaround .

Any responses much appreciated. thanks in advance,
Jason



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux