Are [basic.lookup.elab]/2 and [basic.scope.pdecl](7.2) in contradiction

1,451 views
Skip to first unread message

Ayrosa

unread,
Mar 25, 2019, 9:48:07 AM3/25/19
to ISO C++ Standard - Discussion
The apparent contradiction stems from the highlighted text in these two paragraphs

[basic.lookup.elab]/2:

If the elaborated-type-specifier has no nested-name-specifier, and unless the elaborated-type-specifier appears in a declaration with the following form:
class-key attribute-specifier-seq identifier ;
the identifier is looked up according to [basic.lookup.unqual] but ignoring any non-type names that have been declared.
 
If the elaborated-type-specifier is introduced by the enum keyword and this lookup does not find a previously declared type-name, the elaborated-type-specifier is ill-formed.
 
If the elaborated-type-specifier is introduced by the class-key and this lookup does not find a previously declared type-name, or if the elaborated-type-specifier appears in a declaration with the form:
class-key attribute-specifier-seq identifier ;
the elaborated-type-specifier is a declaration that introduces the class-name as described in [basic.scope.pdecl].





for an elaborated-type-specifier of the form
class-key identifier
if the elaborated-type-specifier is used in the decl-specifier-seq or parameter-declaration-clause of a function defined in namespace scope, the identifier is declared as a class-name in the namespace that contains the declaration; otherwise, except as a friend declaration, the identifier is declared in the smallest namespace or block scope that contains the declaration.
 
[Note
: 
These rules also apply within templates.
 —end note
]
 
[Note
: 
Other forms of elaborated-type-specifier do not declare a new name, and therefore must refer to an existing type-name.
  —end note
]


The reason for this post came from this question of mine in Stackoverflow., more specifically from the answer by Barry and my comment to his answer.

Brian Bi

unread,
Mar 25, 2019, 10:51:07 AM3/25/19
to std-dis...@isocpp.org
[basic.scope.pdecl]/7 begins "The point of declaration for a class first declared in an elaborated-type-specifier is as follows:"

In your question, the use of the elaborated-type-specifier in the declaration `void f(struct S&);` in the second snippet does not declare the class name because the lookup finds a previously declared type-name (according to [basic.lookup.elab]/2), so [basic.scope.pdecl]/7 doesn't apply.

--

---
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-discussio...@isocpp.org.
To post to this group, send email to std-dis...@isocpp.org.
Visit this group at https://groups.google.com/a/isocpp.org/group/std-discussion/.


--
Brian Bi

Ayrosa

unread,
Mar 26, 2019, 8:47:38 AM3/26/19
to ISO C++ Standard - Discussion
I took me sometime to really grasp what you wrote below. Thanks for the excellent answer.
Reply all
Reply to author
Forward
0 new messages