[Bug c++/84727] New: [8 regression] Constant class initialization not detected as such
romain.geissler at amadeus dot com
gcc-bugzilla@gcc.gnu.org
Mon Mar 5 23:02:00 GMT 2018
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=84727
Bug ID: 84727
Summary: [8 regression] Constant class initialization not
detected as such
Product: gcc
Version: 8.0.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: romain.geissler at amadeus dot com
Target Milestone: ---
Hi,
There appear to be a recent regression, triggered when compiling tcmalloc. This
snippet:
#include <stdint.h>
// A safe way of doing "(1 << n) - 1" -- without worrying about overflow
// Note this will all be resolved to a constant expression at compile-time
#define N_ONES_(IntType, N) \
( (N) == 0 ? 0 : ((static_cast<IntType>(1) << ((N)-1))-1 + \
(static_cast<IntType>(1) << ((N)-1))) )
template <int> class A
{
public:
static const int kValuebits = 7;
private:
// With the template version, this fails.
static const uint32_t kValueMask = N_ONES_(uint32_t, kValuebits);
};
class B
{
public:
static const int kValuebits = 7;
private:
// With the non-template version, this works.
static const uint32_t kValueMask = N_ONES_(uint32_t, kValuebits);
};
used to build fine (with no special options) with g++ (GCC) 8.0.1 20180224
(experimental) but fails with g++ (GCC) 8.0.1 20180301 (experimental):
file.cpp:7:59: error: non-constant in-class initialization invalid for static
member 'A<<anonymous> >::kValueMask'
(static_cast<IntType>(1) << ((N)-1))) )
^
file.cpp:16:44: note: in expansion of macro 'N_ONES_'
static const uint32_t kValueMask = N_ONES_(uint32_t, kValuebits);
^~~~~~~
file.cpp:7:59: note: (an out of class initialization is required)
(static_cast<IntType>(1) << ((N)-1))) )
^
file.cpp:16:44: note: in expansion of macro 'N_ONES_'
static const uint32_t kValueMask = N_ONES_(uint32_t, kValuebits);
^~~~~~~
Cheers,
Romain
More information about the Gcc-bugs
mailing list