Skip to content

Commit

Permalink
Fix Wreserved-identifier for UDLs in Catch2
Browse files Browse the repository at this point in the history
See #578
  • Loading branch information
horenmar committed Aug 19, 2021
1 parent edad4d0 commit 4113a12
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
17 changes: 17 additions & 0 deletions docs/contributing.md
Expand Up @@ -239,6 +239,23 @@ there is no difference is wrong, QNX and VxWorks won't compile if you
include the header as `<cfoo>` and call the function unqualified.


#### User-Defined Literals (UDL) for Catch2' types

Due to messy standardese and ... not great ... implementation of
`-Wreserved-identifier` in Clang, avoid declaring UDLs as
```cpp
Approx operator "" _a(long double);
```
and instead declare them as
```cpp
Approx operator ""_a(long double);
```

Notice that the second version does not have a space between the `""` and
the literal suffix.



### New source file template

If you are adding new source file, there is a template you should use.
Expand Down
4 changes: 2 additions & 2 deletions src/catch2/catch_approx.hpp
Expand Up @@ -114,8 +114,8 @@ namespace Catch {
};

namespace literals {
Approx operator "" _a(long double val);
Approx operator "" _a(unsigned long long val);
Approx operator ""_a(long double val);
Approx operator ""_a(unsigned long long val);
} // end namespace literals

template<>
Expand Down
4 changes: 2 additions & 2 deletions src/catch2/internal/catch_stringref.hpp
Expand Up @@ -98,12 +98,12 @@ namespace Catch {
};


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

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

Expand Down

0 comments on commit 4113a12

Please sign in to comment.