I think that the the variable declared as const
applies only Static Initialization
. I've written the following:
#include <cstdlib>
#include <iostream>
struct A{ };
const A *i = new A();
int main(){ }
and it works fine.
But I expected that the the code is invalid because new A()
is a new-expression
and it is not a constant expression
. Actually:
sec. 5.19/2 N3797:
A conditional-expression e is a core constant expression unless the evaluation of e, following the rules of the abstract machine (1.9), would evaluate one of the following expressions:
[...]
— a new-expression (5.3.4);[...]
and
A constant expression is either a glvalue core constant expression whose value refers to an object with static storage duration or to a function,