Is the following C++11 translation unit well-formed?
typedef int T;
::T i;
If so, it doesn't appear to match the standard grammar.
The simple-type-specifier
should match ::T
, but the grammar is:
simple-type-specifier:
nested-name-specifier_opt type-name
and a nested-name-specifier
cannot match ::
alone, so simple-type-specifier
cannot match ::T
.
Is this a standard defect?
A "declaration" establishes an association between a particular variable, function, or type and its attributes. Overview of Declarations gives the ANSI syntax for the declaration nonterminal. A declaration also specifies where and when an identifier can be accessed (the "linkage" of an identifier).
The first declares a function f that takes two integer arguments and has a return type of void : void f(int, int); This fragment declares a pointer p1 to a function that takes a pointer to a constant character and returns an integer: int (*p1) (const char*);
The declare construct is used for embedding declarations within executable code. Global declarations and declarations that are computed by a program are established by the proclaim construct.
Scope resolution operator :: (C++ only) The :: (scope resolution) operator is used to qualify hidden names so that you can still use them. You can use the unary scope operator if a namespace scope or global scope name is hidden by an explicit declaration of the same name in a block or class.
The function declaration (function statement) defines a function with the specified parameters. You can also define functions using the Function constructor and a function expression.
Variable declaration in C++ is a part which is done in the starting only to ensure the compiler that there is some variable with the given type and name used in the program so that it can proceed with the further compilation without giving any issues. A variable in C++ is declared before its first use in the program.
Use auto and decltype to declare a function template whose return type depends on the types of its template arguments. Or, use auto and decltype to declare a function template that wraps a call to another function, and then returns the return type of the wrapped function.
This is a specification defect. It is fixed in the latest draft, N3691 (PDF), where nested-name-specifier is:
nested-name-specifier:
::
type-name ::
namespace-name ::
decltype-specifier ::
nested-name-specifier identifier ::
nested-name-specifier templateopt simple-template-id ::
(In C++11, the first production, nested-name-specifier -> ::
, is missing.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With