language lawyer - Nested static constexpr of incomplete type. Valid C++ or not? -



language lawyer - Nested static constexpr of incomplete type. Valid C++ or not? -

clang , gcc disagree on whether next code valid c++11 or not:

struct thing { int value; static const thing thing; }; constexpr thing thing::thing {3};

clang compiles , gnu gcc version 4.7.2 says: error: redeclaration ‘thing::thing’ differs in ‘constexpr’ constexpr thing thing::thing {3};

which compiler's interpretation of standard correct? , seem c++14 standard going have new relating matter?

introduction

the snippet legal c++11, , there no alter in c++14.

note: gcc 4.9.0 correctly accepts snippet, ie. rejecting snippet bug in previous versions of compiler.

explanation

the constexpr specifier affects object beingness defined (it declared const), in particular specifier mandates object declared;

is literal type, and; has initializer, and; that initializer constant expression.

struct thing { int value; static const thing thing; // (a) }; constexpr thing thing::thing {3}; // (b)

this means definition (b) refers object of type thing const named thing, same (a), hence; snippet legal.

7.1.5p9 the constexpr specifier [dcl.constexpr] (n3337)

a constexpr specifier used in object declaration declares object const. such object shall have literal type , shall initialized.

c++ language-lawyer static-members constexpr

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

c# - Create a Notification Object (Email or Page) At Run Time -- Dependency Injection or Factory -

Set Up Of Common Name Of SSL Certificate To Protect Plesk Panel -