0

first at all, let's see the standard(ISO/IEC 14882:2011(E))

[reserved.names](17.6.4.3) said:

1 The C++ standard library reserves the following kinds of names:
— macros
— global names
— names with external linkage

2 If a program declares or defines a name in a context where it is reserved, other than as explicitly allowed by this Clause, its behavior is undefined.

[global.names](17.6.4.3.2) said:

1 Certain sets of names and function signatures are always reserved to the implementation:
— Each name that contains a double underscore __ or begins with an underscore followed by an uppercase letter (2.12) is reserved to the implementation for any use.
— Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace.

Q1: what is explicitly allowed in [reserved.names]/2 or in which case a name is explicitly allowed?

Q2: Does that means we can use a name that begins with an underscore followed by an lowercase letter in local namespace? If so is that so-called explicitly allowed?

iTruth
  • 123
  • 7
  • 3
    `_a1` and `_A1` are both names that begin with an underscore and are in the global namespace. What is unclear about the statement "Each name that begins with an underscore is reserved to the implementation for use as a name in the global namespace." or how it applies to those identifiers? – Nathan Pierson Dec 14 '22 at 08:25
  • @NathanPierson what about _a2 and _A2? – iTruth Dec 14 '22 at 08:26
  • More generally, the thrust of this question appears to be "I know there _isn't_ a rule that says I _can't_ use this identifier in this context, but is there a rule that explicitly says I _can_?" I mean, can you point to the part that **explicitly allows** you to use `foo` as an identifier? – Nathan Pierson Dec 14 '22 at 08:28
  • 1
    The question you link to includes a longer passage about reserved identifiers with the following line: "No other identifiers are reserved." So if your identifier doesn't fall under the rules forbidding its use, it's not a reserved identifier. `_A2` is reserved because it's an underscore followed by a capital letter, `_a2` is not reserved. This is all covered by your linked question. – Nathan Pierson Dec 14 '22 at 08:30
  • @NathanPierson what I read is C++11 standard and he provide C++03 standard. I can't find "No other identifiers are reserved." in C++11 section [reserved.names] – iTruth Dec 14 '22 at 08:39
  • Well, that line isn't directly from the C++03 standard. It's from the fact that it incorporates parts of the C standard as a normative reference. If we look for the analogous part of [C++11's standard](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3690.pdf), we turn to 1.2/1 where it cites ISO/IEC 9899:1999 as normative. We crack [that](https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf) open and find that 7.1.3.2 includes the same language as in the answer. Nothing different in the C++11 case. – Nathan Pierson Dec 14 '22 at 08:47
  • @NathanPierson by the way, the **explicitly allow** is in [reserved.names](17.6.4.3)/2, of course we don't need to find the part that explicitly allows you to use foo as an identifier, but in this case, the standard said If a program declares or defines a name in a context where it is reserved, other than as **explicitly allowed** by this Clause, its behavior is undefined. so I have to know what is **explicitly allowed** in here – iTruth Dec 14 '22 at 08:49
  • 1
    I'd suggest editing this question to be narrowly focused on the meaning of the phrase "other than as explicitly allowed by this Clause", because right now the vast majority of the question is adequately answered by the duplicate. – Nathan Pierson Dec 14 '22 at 08:51
  • Anyway the thing with `_a2` is that it when it comes to the passage "If a program declares or defines a name in a context where it is reserved, other than as explicitly allowed by this Clause, its behavior is undefined", you don't need to worry about whether the "other than as..." part comes into effect or not, because _it's not reserved_.. The standard specifies two things that are reserved: Names that start with double underscore or underscore-uppercase anywhere, and names that begin with an underscore in the global namespace. `_a2` in your code isn't either of those. – Nathan Pierson Dec 14 '22 at 09:00
  • you do not need to add "Edit" to an edit. The edit history can be seen here https://stackoverflow.com/posts/74795121/revisions if someone cares. You added a small paragraph, but the title is still the old, and when first reading I completely missed that the most part of the answer is old. By reading the question I did not understand it (i didnt read all comments) – 463035818_is_not_an_ai Dec 14 '22 at 09:00
  • But if you're going "Okay but what if there are secret additional rules that might make `_a2` reserved", well, why not imagine that there are secret additional rules that would make `foo` reserved? – Nathan Pierson Dec 14 '22 at 09:00
  • @NathanPierson I think you're right. but I really care about semantic correctness. even there is really have a secret additional rules that might make _a2 reserved, I have to find it. – iTruth Dec 14 '22 at 09:17

0 Answers0