Skip to content

Conversation

@pps83
Copy link
Contributor

@pps83 pps83 commented Mar 24, 2025

Fixes this warning from clang:

In file included from D:/src/test.cpp:6:
D:/src/intx/include/intx/intx.hpp:1622:1: warning: identifier '_u128' preceded by whitespace in a literal operator declaration is deprecated [-Wdeprecated-literal-operator]
 1622 | DEFINE_ALIAS_AND_LITERAL(128);
      | ^
D:/src/intx/include/intx/intx.hpp:1617:34: note: expanded from macro 'DEFINE_ALIAS_AND_LITERAL'
 1617 |     consteval uint##N operator"" _u##N(const char* s) \
      |                                  ^
<scratch space>:168:1: note: expanded from here
  168 | _u128

Fixes this warning from clang:
```
In file included from D:/src/test.cpp:6:
D:/src/intx/include/intx/intx.hpp:1622:1: warning: identifier '_u128' preceded by whitespace in a literal operator declaration is deprecated [-Wdeprecated-literal-operator]
 1622 | DEFINE_ALIAS_AND_LITERAL(128);
      | ^
D:/src/intx/include/intx/intx.hpp:1617:34: note: expanded from macro 'DEFINE_ALIAS_AND_LITERAL'
 1617 |     consteval uint##N operator"" _u##N(const char* s) \
      |                                  ^
<scratch space>:168:1: note: expanded from here
  168 | _u128
```
@pps83 pps83 force-pushed the literal-fix branch 2 times, most recently from f7d3446 to 66a5720 Compare March 24, 2025 13:34
@pps83
Copy link
Contributor Author

pps83 commented Mar 24, 2025

fyi, pr for a similar fix for msvc's new preoprocessor in boost::mp boostorg/multiprecision#667

}

#define INTX_JOIN2(X, Y) X##Y
#define INTX_JOIN1(X, Y) INTX_JOIN2(X, Y)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need two levels of these JOIN macros?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need two levels of these JOIN macros?

I didn't make it that way because I was bored :) At first I took whatever was from boost, and their join is 3-step nowadays:

#define BOOST_JOIN(X, Y) BOOST_DO_JOIN(X, Y)
#define BOOST_DO_JOIN(X, Y) BOOST_DO_JOIN2(X,Y)
#define BOOST_DO_JOIN2(X, Y) X##Y

whatever I did, I couldn't make it with 1 or 2 defines. I was already convinced that there was no way to avoid the warning in the first place, but then figured out what makes msvc happy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did a bit more tinkering, and just got rid of one join

using uint##N = uint<N>; \
namespace literals \
{ \
consteval uint##N INTX_LITERAL(N)(const char* s) \
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
consteval uint##N INTX_LITERAL(N)(const char* s) \
consteval uint##N INTX_JOIN(operator"", _u##N)(const char* s) \

will this work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, works. pr updated

@sonarqubecloud
Copy link

Copy link
Owner

@chfast chfast left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome, thanks very much for solving this issue.

@chfast chfast merged commit 1ca9554 into chfast:master Mar 24, 2025
18 checks passed
@pps83 pps83 deleted the literal-fix branch March 24, 2025 15:40
@JasonCoombs
Copy link

JasonCoombs commented Apr 5, 2025

Looking at this and trying to determine if my build is using the new commit or if it's building the older code in Hunter.

On MacOS with clang seeing this error from DEFINE_ALIAS_AND_LITERAL(128):

/Users/jason/intx/test/unittests/test_div.cpp:58:34: error: constexpr variable 'div_test_cases' must be initialized by a constant expression
   58 | constexpr div_test_case<uint512> div_test_cases[] = {
      |                                  ^                  ~
   59 |     {2, 1, 2, 0},
      |     ~~~~~~~~~~~~~
   60 |     {
      |     ~
   61 |         0x10000000000000000_u512,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~~
   62 |         2,
      |         ~~
   63 |         0x8000000000000000_u512,
      |         ~~~~~~~~~~~~~~~~~~~~~~~~
   64 |         0,
      |         ~~
   65 |     },
      |     ~~
   66 |     {
      |     ~
   67 |         0x7000000000000000,
      |         ~~~~~~~~~~~~~~~~~~~
   68 |         0x8000000000000000,
      |         ~~~~~~~~~~~~~~~~~~~
   69 |         0,
      |         ~~
   70 |         0x7000000000000000,
      |         ~~~~~~~~~~~~~~~~~~~
   71 |     },
      |     ~~
   72 |     {
      |     ~
   73 |         0x8000000000000000,
      |         ~~~~~~~~~~~~~~~~~~~
/Users/jason/intx/include/intx/intx.hpp:807:13: note: constexpr evaluation hit maximum step limit; possible infinite loop?
  807 |             x = (x << uint64_t{4}) | from_hex_digit(c);
      |             ^
/Users/jason/intx/include/intx/intx.hpp:1623:1: note: in call to 'from_string<intx::uint<128>>(&"0x800000000000007fc000000000007f80"[0])'
 1623 | DEFINE_ALIAS_AND_LITERAL(128);
      | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/Users/jason/intx/include/intx/intx.hpp:1620:16: note: expanded from macro 'DEFINE_ALIAS_AND_LITERAL'
 1620 |         return from_string<uint##N>(s);                           \
      |                ^~~~~~~~~~~~~~~~~~~~~~~
/Users/jason/intx/test/unittests/test_div.cpp:308:9: note: in call to 'operator""_u128(&"0x800000000000007fc000000000007f80"[0])'
  308 |         0x800000000000007fc000000000007f80_u128,
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Documentation: https://clang.llvm.org/docs/UsersManual.html#controlling-implementation-limits

@JasonCoombs
Copy link

I don't understand why the template instantiation hits this limit, but it apparently does when building with clang on MacOS.

-fconstexpr-steps=N
Sets the limit for the number of full-expressions evaluated in a single constant expression evaluation. This also controls the maximum size of array and dynamic array allocation that can be constant evaluated. The default is 1048576.

See: https://clang.llvm.org/docs/UsersManual.html#controlling-implementation-limits

I added this to CMakeLists.txt and the build succeeded. Can't tell if this is newly-introduced behaviour with this commit, I am new here.

add_compile_options("-fconstexpr-depth=4096" "-fconstexpr-steps=4000000")

@chfast
Copy link
Owner

chfast commented Apr 7, 2025

This is different issue. Quick fix is to change constexpr to static at the div_test_cases.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants