简体   繁体   中英

The term `function declaration` is defined in §7/9 (N4140), but it isn't defined as a grammar production. Why?

In §7/9 you'll find the definition of a function declaration :

If the decl-specifier-seq contains no typedef specifier, the declaration is called a function declaration if the type associated with the name is a function type (8.3.5) and an object declaration otherwise.

In §7/1 you can find the definition of the grammar-production declaration , but there is no function-declaration nominated in there, as part of this definition. In other words, how would one classify function declaration in the C++ grammar?

Since that paragraph talks about init-declarators , I take it to apply to a simple-declaration in which there is an init-declarator-list . You can see that this is not entirely correct

// clearly, this is not the declaration of an object, so it should
// not be called an "object declaration", but 7p9 does say so
int &a = x;

struct A {
   // AFAICS 7p9 should also apply here, but there is no init-declarator
   // here, but a member-declarator. 9.2 also doesn't delegate to 7p9.
   typedef int a;
};

A consequence is that the following also contains a function declaration, but that declaration declares not a function.

template<typename T> void f();

In summary, I think there is some clarification on this text desired in the spec.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM