https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80739
Bug ID: 80739 Summary: Accessing value of X through a Y glvalue in a constant expression Product: gcc Version: 6.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: vince.rev at gmail dot com Target Milestone: --- Created attachment 41352 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41352&action=edit Example of the bug Consider the following valid code in C++14 (compiles without problem under clang): // ========================================================================== // #include <iostream> template <class T> struct element { constexpr element() noexcept: x0(0), x1(0), x2(0), x3(0) {} T x0; int x1, x2, x3; }; template <class T> struct container { constexpr container() noexcept: data() {data = element<T>();} element<T> data; }; template <class T> constexpr bool test() { return (container<T>(), true); } int main() { constexpr bool tmp0 = test<int>(); // works constexpr bool tmp1 = test<std::size_t>(); // fails return tmp0 && tmp1; } // ========================================================================== // Compilation fails under g++-5 (g++-5 (Ubuntu 5.4.1-2ubuntu1~16.04) 5.4.1 20160904) with the following message: ## -------------------------------------------------------------------------- ## gcc_compiler_error.cpp: In function ‘int main()’: gcc_compiler_error.cpp:16:44: in constexpr expansion of ‘test<long unsigned int>()’ gcc_compiler_error.cpp:16:45: in constexpr expansion of ‘container<long unsigned int>()’ gcc_compiler_error.cpp:16:45: internal compiler error: unexpected expression ‘*(container<long unsigned int>*)this’ of kind mem_ref constexpr bool tmp1 = test<std::size_t>(); // fails ^ Please submit a full bug report, with preprocessed source if appropriate. See <file:///usr/share/doc/gcc-5/README.Bugs> for instructions. ## -------------------------------------------------------------------------- ## Compilation fails under g++-6 (g++-6 (Ubuntu 6.2.0-3ubuntu11~16.04) 6.2.0 20160901) with the following message: ## -------------------------------------------------------------------------- ## gcc_compiler_error.cpp: In function ‘int main()’: gcc_compiler_error.cpp:16:44: in constexpr expansion of ‘test<long unsigned int>()’ gcc_compiler_error.cpp:16:45: in constexpr expansion of ‘container<long unsigned int>()’ gcc_compiler_error.cpp:16:45: error: accessing value of ‘<anonymous>’ through a ‘char [20]’ glvalue in a constant expression constexpr bool tmp1 = test<std::size_t>(); // fails ^ ## -------------------------------------------------------------------------- ## Other versions may be affected (not tested).