8

The C++ Standard reserves names beginning with an underscore followed by a capital letter in all scopes.

Does this apply to user literal operators?

e.g.

int _MyInt; // reserved, violation

template < char... >
auto operator "" _MyInt ( ); // reserved???
François Andrieux
  • 28,148
  • 6
  • 56
  • 87
  • Personally, I'd just stay on the safe side and stick to lower-case. – Jesper Juhl Jun 03 '20 at 18:16
  • 1
    If that's allowed, it looks like the C++ implementation should avoid defining any macros starting with underscore + capital letter in the standard libraries (?) – chi Jun 03 '20 at 18:50
  • @chi They can always `#undef` I suppose –  Jun 03 '20 at 18:51
  • 1
    Does this answer your question? [Is every "normal" use of user-defined literals undefined behavior?](https://stackoverflow.com/questions/59180353/is-every-normal-use-of-user-defined-literals-undefined-behavior) – Asteroids With Wings Jun 03 '20 at 18:54
  • @AsteroidsWithWings As the comment on an answer to the question you posted says, cases like `_Foo` are not covered, which is what this question is asking. – cigien Jun 03 '20 at 18:56
  • Given that clang forbids `template < char... > auto operator "" _ExtInt ( );`, I'd say it does apply in practice. – cpplearner Jun 04 '20 at 06:51

1 Answers1

4

No, it allows the use of an underscore followed by a capital letter (which is otherwise a reserved identifier).

Source

I've only found an example, not a formal paragraph, in the standard supporting the above:

[over.literal]

double operator""_Bq(long double);    // OK: does not use the reserved identifier _­Bq
double operator"" _Bq(long double);   // uses the reserved identifier _­Bq 

So, as long as you don't put a space between "" and _Ud it's ok - according to the example that is.

Ted Lyngmo
  • 93,841
  • 5
  • 60
  • 108
  • Comments are not for extended discussion; this conversation has been [moved to chat](https://chat.stackoverflow.com/rooms/215268/discussion-on-answer-by-ted-lyngmo-reserved-names-user-literals). – Samuel Liew Jun 04 '20 at 02:36