Skip to content

Commit 8a8363a

Browse files
committed
[clang][bytecode] Don't diagnose defined functions that will have a body
But don't have one, yet. That happens for class methods, which are "defined" but have no body, hence they willHaveBody. Fixes #164995
1 parent 750a583 commit 8a8363a

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

clang/lib/AST/ByteCode/Interp.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -994,10 +994,12 @@ static bool CheckCallable(InterpState &S, CodePtr OpPC, const Function *F) {
994994
S.checkingPotentialConstantExpression())
995995
return false;
996996

997-
// If the declaration is defined, declared 'constexpr' _and_ has a body,
998-
// the below diagnostic doesn't add anything useful.
997+
// If the declaration is defined, declared 'constexpr' _and_
998+
// has (or will have) a body, the below diagnostic doesn't add anything
999+
// useful.
9991000
if (DiagDecl->isDefined() && DiagDecl->isConstexpr() &&
1000-
DiagDecl->hasBody())
1001+
(DiagDecl->doesThisDeclarationHaveABody() ||
1002+
DiagDecl->willHaveBody()))
10011003
return false;
10021004

10031005
S.FFDiag(S.Current->getLocation(OpPC),

clang/test/AST/ByteCode/records.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1861,3 +1861,12 @@ namespace PrimitiveInitializedByInitList {
18611861
} c{ 17 };
18621862
static_assert(c.b == 17, "");
18631863
}
1864+
1865+
namespace MethodWillHaveBody {
1866+
class A {
1867+
public:
1868+
static constexpr int get_value2() { return 1 + get_value(); }
1869+
static constexpr int get_value() { return 1; }
1870+
};
1871+
static_assert(A::get_value2() == 2, "");
1872+
}

0 commit comments

Comments
 (0)