aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorcor3ntin <corentinjabot@gmail.com>2025-03-18 20:50:56 +0100
committerGitHub <noreply@github.com>2025-03-18 20:50:56 +0100
commitbc8b19c7575f3882b7655e129d4fc3b74c7fbba3 (patch)
treee98d3b2ebf5eb87bb8a2491964b54faa46b96355 /clang/lib/AST/ExprConstant.cpp
parent0619892cab8a5cc24e25f7eddcff7316757a1ff0 (diff)
downloadllvm-bc8b19c7575f3882b7655e129d4fc3b74c7fbba3.zip
llvm-bc8b19c7575f3882b7655e129d4fc3b74c7fbba3.tar.gz
llvm-bc8b19c7575f3882b7655e129d4fc3b74c7fbba3.tar.bz2
[Clang] Introduce a trait to determine the structure binding size (#131515)
Introduce a trait to determine the number of bindings that would be produced by ```cpp auto [...p] = expr; ``` This is necessary to implement P2300 (https://eel.is/c++draft/exec#snd.concepts-5), but can also be used to implement a general get<N> function that supports aggregates `__builtin_structured_binding_size` is a unary type trait that evaluates to the number of bindings in a decomposition If the argument cannot be decomposed, a sfinae-friendly error is produced. A type is considered a valid tuple if `std::tuple_size_v<T>` is a valid expression, even if there is no valid `std::tuple_element` specialization or suitable `get` function for that type. Fixes #46049
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 7803b10..022a201 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12102,7 +12102,12 @@ public:
}
bool VisitTypeTraitExpr(const TypeTraitExpr *E) {
- return Success(E->getValue(), E);
+ if (E->isStoredAsBoolean())
+ return Success(E->getBoolValue(), E);
+ if (E->getAPValue().isAbsent())
+ return false;
+ assert(E->getAPValue().isInt() && "APValue type not supported");
+ return Success(E->getAPValue().getInt(), E);
}
bool VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *E) {