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

[ADT] [NFC] Resolve a potential overload ambiguity in the ADT unit tests #85341

Closed
wants to merge 1 commit into from

Conversation

wolfy1961
Copy link
Collaborator

Some compilers (ex. VS2019 and VS2022) report an overload resolution error with the APInt constructor.
Resolve the ambiguity with a static_cast.

@llvmbot
Copy link
Collaborator

llvmbot commented Mar 15, 2024

@llvm/pr-subscribers-llvm-adt

Author: Wolfgang Pieb (wolfy1961)

Changes

Some compilers (ex. VS2019 and VS2022) report an overload resolution error with the APInt constructor.
Resolve the ambiguity with a static_cast.


Full diff: https://github.com/llvm/llvm-project/pull/85341.diff

1 Files Affected:

  • (modified) llvm/unittests/ADT/APIntTest.cpp (+1-1)
diff --git a/llvm/unittests/ADT/APIntTest.cpp b/llvm/unittests/ADT/APIntTest.cpp
index 400313a6234677..c3805431e6b2b6 100644
--- a/llvm/unittests/ADT/APIntTest.cpp
+++ b/llvm/unittests/ADT/APIntTest.cpp
@@ -2918,7 +2918,7 @@ TEST(APIntTest, Average) {
   APInt A100(32, 100);
   APInt A101(32, 101);
   APInt A200(32, 200, false);
-  APInt ApUMax(32, UINT_MAX, false);
+  APInt ApUMax(32, static_cast<uint64_t>(UINT_MAX), false);
 
   EXPECT_EQ(APInt(32, 150), APIntOps::avgFloorU(A100, A200));
   EXPECT_EQ(APIntOps::RoundingUDiv(A100 + A200, A2, APInt::Rounding::DOWN),

@wolfy1961 wolfy1961 requested a review from kuhar March 15, 2024 00:41
@@ -2918,7 +2918,7 @@ TEST(APIntTest, Average) {
APInt A100(32, 100);
APInt A101(32, 101);
APInt A200(32, 200, false);
APInt ApUMax(32, UINT_MAX, false);
APInt ApUMax(32, static_cast<uint64_t>(UINT_MAX), false);
Copy link
Member

@kuhar kuhar Mar 15, 2024

Choose a reason for hiding this comment

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

How about

Suggested change
APInt ApUMax(32, static_cast<uint64_t>(UINT_MAX), false);
APInt ApUMax(32, static_cast<uint64_t>(std::numeric_limits<uint32_t>::max()), false);

or

Suggested change
APInt ApUMax(32, static_cast<uint64_t>(UINT_MAX), false);
APInt ApUMax(32, (~(uint64_t(0)) >> 32, false);

to avoid a system-specific definition of uint?

Copy link
Collaborator

Choose a reason for hiding this comment

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

This would be my preferred option:

APInt ApUMax = APInt::getMaxValue(32);

@RKSimon
Copy link
Collaborator

RKSimon commented Mar 15, 2024

I ended up pushing a fix here to unblock some other people upstream: 41bdcaa

@wolfy1961 wolfy1961 closed this Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants