Author: Fangrui Song
Date: 2026-11-27T13:05:37-08:00
New Revision: e6091a8158c863643d4fbe44b70fe62dd0ef3eba

URL: 
https://github.com/llvm/llvm-project/commit/e6091a8158c863643d4fbe44b70fe62dd0ef3eba
DIFF: 
https://github.com/llvm/llvm-project/commit/e6091a8158c863643d4fbe44b70fe62dd0ef3eba.diff

LOG: [AST] Make CharUnits ctor constexpr (#246737)

Fix a -Wglobal-constructors in HLSLBufferLayoutBuilder.cpp

Added: 
    

Modified: 
    clang/include/clang/AST/CharUnits.h
    clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/CharUnits.h 
b/clang/include/clang/AST/CharUnits.h
index 4163aed97545ca..8aaae4de4c8cce 100644
--- a/clang/include/clang/AST/CharUnits.h
+++ b/clang/include/clang/AST/CharUnits.h
@@ -42,7 +42,7 @@ class CharUnits {
 private:
   QuantityType Quantity = 0;
 
-  explicit CharUnits(QuantityType C) : Quantity(C) {}
+  explicit constexpr CharUnits(QuantityType C) : Quantity(C) {}
 
 public:
   /// A default constructor.
@@ -55,7 +55,7 @@ class CharUnits {
   static CharUnits One() { return CharUnits(1); }
 
   /// Construct a CharUnits quantity from a raw integer type.
-  static CharUnits fromQuantity(QuantityType Quantity) {
+  static constexpr CharUnits fromQuantity(QuantityType Quantity) {
     return CharUnits(Quantity);
   }
 

diff  --git a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp 
b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp
index b09fc4c91df2a9..e55de8b0692e24 100644
--- a/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp
+++ b/clang/lib/CodeGen/HLSLBufferLayoutBuilder.cpp
@@ -21,7 +21,7 @@
 using namespace clang;
 using namespace clang::CodeGen;
 
-static const CharUnits CBufferRowSize =
+constexpr CharUnits CBufferRowSize =
     CharUnits::fromQuantity(llvm::hlsl::CBufferRowSizeInBytes);
 
 namespace clang {


        
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to