Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use of reserved identifiers #578

Closed
melak47 opened this issue Jan 25, 2016 · 10 comments
Closed

Use of reserved identifiers #578

melak47 opened this issue Jan 25, 2016 · 10 comments

Comments

@melak47
Copy link
Contributor

melak47 commented Jan 25, 2016

A quick scan shows at least __catchResult and ____C_A_T_C_H____T_E_S_T____ being used,
but since these identifiers contain double underscores, they are reserved for
the compiler/stdlib implementation: [lex.name] 2.10.3 ([global.names] 17.6.4.3.2 until C++17)

@horenmar
Copy link
Member

Not really a bug, but more of a language lawyer request.

@AndrewPaxie
Copy link

LLVM commit b83b23275b745287bf9d3d72a93b593119f53f75 introduces
warning -Wreserved-identifier.
See: https://reviews.llvm.org/D93095
This is devastating to projects using Catch that compile with -Weverything on the Clang command line.
Example: trompeloeil.

@j-stephan
Copy link

j-stephan commented Aug 11, 2021

This is devastating to projects using Catch that compile with -Weverything on the Clang command line.

Indeed. Once clang 14 13 becomes more widely used a lot of people will run into this.

@davidstone
Copy link

Trying to set up a new project using the add_subdirectory CMake integration. I immediately run into this error because my project builds with this warning. This is using the Catch2 v3 devel branch.

In file included from /home/david/tm/Catch2/src/catch2/../catch2/catch_test_macros.hpp:11:
In file included from /home/david/tm/Catch2/src/catch2/../catch2/internal/catch_test_macro_impl.hpp:11:
In file included from /home/david/tm/Catch2/src/catch2/../catch2/internal/catch_assertion_handler.hpp:11:
In file included from /home/david/tm/Catch2/src/catch2/../catch2/catch_assertion_info.hpp:13:
/home/david/tm/Catch2/src/catch2/../catch2/internal/catch_stringref.hpp:101:32: error: identifier '_sr' is reserved because it starts with '_' at global scope [-Werror,-Wreserved-identifier]
    constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
                   ~~~~~~~~~~~~^~~
                   operator""_sr
/home/david/tm/Catch2/src/catch2/../catch2/internal/catch_stringref.hpp:106:28: error: identifier '_catch_sr' is reserved because it starts with '_' at global scope [-Werror,-Wreserved-identifier]
constexpr auto operator "" _catch_sr( char const* rawChars, std::size_t size ) noexcept -> Catch::StringRef {
               ~~~~~~~~~~~~^~~~~~~~~
               operator""_catch_sr
2 errors generated.

@melak47
Copy link
Contributor Author

melak47 commented Aug 18, 2021

Not really a bug, but more of a language lawyer request.

I'd be happy to open a PR, if it would be welcome?

@horenmar
Copy link
Member

@melak47 It is already done for v3, but I am willing to merge it for v2 (I don't like backporting v3->v2 and IIRC I got bunch of merge conflicts from it).

@davidstone That seems like bad implementation in Clang, because both are UDLs, which are not even allowed to start without a leading _, and _sr is inside a namespace:

constexpr auto operator "" _sr( char const* rawChars, std::size_t size ) noexcept -> StringRef {
return StringRef( rawChars, size );
}

@AndrewPaxie
Copy link

AndrewPaxie commented Aug 18, 2021

@horenmar Nice to hear v3 provides a fix. I was surprised by the quality of implementation problems in Clang. We will have to hussle to make any meaningful change in Clang-13, least there is another warning that is useless on release. 13.0.0-rc2 is scheduled for release 24 August 2021, -rc3 on 7 September 2021, and final on 21 September 2021, based on the schedule at http://llvm.org.

We can follow the progress of this bug report: https://bugs.llvm.org/show_bug.cgi?id=50644

@davidstone
Copy link

@horenmar: The issue is the space between the "" and the UDL name. This causes a warning because having that space there exposes you to macro expansion, see https://bugs.llvm.org/show_bug.cgi?id=50644. Defining your UDLs as operator ""_catch_sr and operator ""_sr make the warning go away.

@bernhardmgruber
Copy link
Contributor

The issue is bigger than just UDLs: https://godbolt.org/z/nG9Mn7hKv. If you use e.g. TEMPLATE_LIST_TEST_CASE, then you get additional errors like:

error: identifier '____C_A_T_C_H____T_E_M_P_L_A_T_E____T_E_S_T____F_U_N_C____0' is reserved because it starts with '__' [-Werror,-Wreserved-identifier]
TEMPLATE_LIST_TEST_CASE("", "", Types) {

bernhardmgruber added a commit to bernhardmgruber/Catch2 that referenced this issue Dec 16, 2021
Such identifiers are reserved by the C++ standard.
Fixes part of catchorg#578.
horenmar pushed a commit that referenced this issue Dec 16, 2021
Such identifiers are reserved by the C++ standard.
Fixes part of #578.
@horenmar
Copy link
Member

v3 has been fixed for a while and @bernhardmgruber made PR for v2, so this is done.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants