Skip to content

Conversation

@kazutakahirata
Copy link
Contributor

We have three implementations of ResolveUnderlyingType:

  • enum
  • bool
  • neither

This patch combines the latter two with std::conditional_t.

Without this patch, we use "void" to trigger a compilation failure
downstream when sizeof(bool) != 1, which is not very friendly. This
patch instead uses static_assert to catch the case where the user
chooses to use bool but sizeof(bool) != 1.

We have three implementations of ResolveUnderlyingType:

- enum
- bool
- neither

This patch combines the latter two with std::conditional_t.

Without this patch, we use "void" to trigger a compilation failure
downstream when sizeof(bool) != 1, which is not very friendly.  This
patch instead uses static_assert to catch the case where the user
chooses to use bool but sizeof(bool) != 1.
@llvmbot
Copy link
Member

llvmbot commented Oct 18, 2025

@llvm/pr-subscribers-llvm-adt

Author: Kazu Hirata (kazutakahirata)

Changes

We have three implementations of ResolveUnderlyingType:

  • enum
  • bool
  • neither

This patch combines the latter two with std::conditional_t.

Without this patch, we use "void" to trigger a compilation failure
downstream when sizeof(bool) != 1, which is not very friendly. This
patch instead uses static_assert to catch the case where the user
chooses to use bool but sizeof(bool) != 1.


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

1 Files Affected:

  • (modified) llvm/include/llvm/ADT/Bitfields.h (+3-6)
diff --git a/llvm/include/llvm/ADT/Bitfields.h b/llvm/include/llvm/ADT/Bitfields.h
index 1af276145ba48..1fbc41c472581 100644
--- a/llvm/include/llvm/ADT/Bitfields.h
+++ b/llvm/include/llvm/ADT/Bitfields.h
@@ -154,12 +154,9 @@ struct ResolveUnderlyingType {
   using type = std::underlying_type_t<T>;
 };
 template <typename T> struct ResolveUnderlyingType<T, false> {
-  using type = T;
-};
-template <> struct ResolveUnderlyingType<bool, false> {
-  /// In case sizeof(bool) != 1, replace `void` by an additionnal
-  /// std::conditional.
-  using type = std::conditional_t<sizeof(bool) == 1, uint8_t, void>;
+  static_assert(!std::is_same_v<T, bool> || sizeof(bool) == 1,
+                "T being bool requires sizeof(bool) == 1.");
+  using type = std::conditional_t<std::is_same_v<T, bool>, uint8_t, T>;
 };
 
 } // namespace bitfields_details

@kazutakahirata kazutakahirata merged commit 5a20b72 into llvm:main Oct 19, 2025
12 checks passed
@kazutakahirata kazutakahirata deleted the cleanup_20251018_ADT_Bitfields branch October 19, 2025 00:51
@llvm-ci
Copy link
Collaborator

llvm-ci commented Oct 19, 2025

LLVM Buildbot has detected a new failure on builder clang-m68k-linux-cross running on suse-gary-m68k-cross while building llvm at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/27/builds/17710

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
******************** TEST 'LLVM-Unit :: CAS/./CASTests/2/17' FAILED ********************
Script(shard):
--
GTEST_OUTPUT=json:/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/unittests/CAS/./CASTests-LLVM-Unit-3204612-2-17.json GTEST_SHUFFLE=0 GTEST_TOTAL_SHARDS=17 GTEST_SHARD_INDEX=2 /var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/unittests/CAS/./CASTests
--

Script:
--
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/stage1/unittests/CAS/./CASTests --gtest_filter=CASProgramTest.MappedFileRegionArenaTest
--
Note: Google Test filter = CASProgramTest.MappedFileRegionArenaTest
[==========] Running 1 test from 1 test suite.
[----------] Global test environment set-up.
[----------] 1 test from CASProgramTest
/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/llvm/unittests/CAS/ProgramTest.cpp:147: Failure
Value of: PI.ReturnCode == 0
  Actual: false
Expected: true


/var/lib/buildbot/workers/suse-gary-m68k-cross/clang-m68k-linux-cross/llvm/llvm/unittests/CAS/ProgramTest.cpp:147
Value of: PI.ReturnCode == 0
  Actual: false
Expected: true



********************


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.

4 participants