From 192c2c5c89477e28d0129f37a7d262112585b353 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Timm=20B=C3=A4der?= Date: Fri, 17 Feb 2023 16:56:47 +0100 Subject: [PATCH] [clang][Interp] Ignore StaticAssertDecls They have already been handled before, but we can't just return false when we encounter one. Differential Revision: https://reviews.llvm.org/D144272 --- clang/lib/AST/Interp/ByteCodeStmtGen.cpp | 3 +++ clang/test/AST/Interp/functions.cpp | 19 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp index 1735b9b..6faa3f9 100644 --- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp +++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp @@ -224,6 +224,9 @@ bool ByteCodeStmtGen::visitCompoundStmt( template bool ByteCodeStmtGen::visitDeclStmt(const DeclStmt *DS) { for (auto *D : DS->decls()) { + if (isa(D)) + continue; + const auto *VD = dyn_cast(D); if (!VD) return false; diff --git a/clang/test/AST/Interp/functions.cpp b/clang/test/AST/Interp/functions.cpp index 2b44f42..4b81e7d 100644 --- a/clang/test/AST/Interp/functions.cpp +++ b/clang/test/AST/Interp/functions.cpp @@ -9,11 +9,28 @@ constexpr int gimme5() { static_assert(gimme5() == 5, ""); -template constexpr T identity(T t) { return t; } +template constexpr T identity(T t) { + static_assert(true); + return t; +} static_assert(identity(true), ""); static_assert(identity(true), ""); /// Compiled bytecode should be cached static_assert(!identity(false), ""); +template +constexpr bool sameSize() { + static_assert(sizeof(A) == sizeof(B), ""); // expected-error {{static assertion failed}} \ + // ref-error {{static assertion failed}} \ + // expected-note {{evaluates to}} \ + // ref-note {{evaluates to}} + return true; +} +static_assert(sameSize(), ""); +static_assert(sameSize(), ""); +static_assert(sameSize(), ""); // expected-note {{in instantiation of function template specialization}} \ + // ref-note {{in instantiation of function template specialization}} + + constexpr auto add(int a, int b) -> int { return identity(a) + identity(b); } -- 2.7.4