Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++11 declaration `::T i`?

Tags:

c++

c++11

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?

like image 698
Andrew Tomazos Avatar asked Aug 14 '13 17:08

Andrew Tomazos


People also ask

What is C declaration?

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).

What is function declaration example?

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*);

What is the syntax of declaration?

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.

What is the :: in C++?

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.

What is true function declaration?

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.

What is variable declaration in C++?

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.

What does Decltype auto do?

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.


1 Answers

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.)

like image 134
James McNellis Avatar answered Oct 03 '22 11:10

James McNellis