[Bug c++/83912] New: [constexpr] struct with a pointer to one of its members, returned by a function, is not a constant expression
giu.campana at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Jan 17 07:17:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83912
Bug ID: 83912
Summary: [constexpr] struct with a pointer to one of its
members, returned by a function, is not a constant
expression
Product: gcc
Version: 8.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: giu.campana at gmail dot com
Target Milestone: ---
Created attachment 43159
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43159&action=edit
preprocessed source
The following source is rejected by gcc because c_3 is initialized with a
non-constant expression
======= source test.cpp ========
struct MyClass
{
constexpr MyClass(int i_value)
: m_value(i_value), m_ptr(&m_value)
{ }
constexpr MyClass(const MyClass & i_source)
: m_value(i_source.m_value), m_ptr(&m_value)
{ }
MyClass & operator = (const MyClass & i_source) = delete;
private:
int const m_value;
int const * m_ptr;
};
constexpr auto make_instance(int i_value)
{
return MyClass(i_value);
}
constexpr auto c_1 = MyClass(34);
const auto c_2 = make_instance(34);
constexpr auto c_3 = make_instance(34);
==============
Tried with gcc 7.2 and gcc 8.0.1
compiled with:
g++ test.cpp -Wall -Wextra -fsanitize=undefined
output:
test.cpp:27:38: error: ‘MyClass{34, (&<anonymous>.MyClass::m_value)}’ is not a
constant expression
constexpr auto c_3 = make_instance(34);
g++ -v
Using built-in specs.
COLLECT_GCC=/home/abc/gcc_dev_bin/bin/g++
COLLECT_LTO_WRAPPER=/home/abc/gcc_dev_bin/libexec/gcc/x86_64-pc-linux-gnu/8.0.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../gcc_dev/configure --prefix=/home/abc/gcc_dev_bin
--disable-multilib
Thread model: posix
gcc version 8.0.1 20180116 (experimental) (GCC)
More information about the Gcc-bugs
mailing list