File tree Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Expand file tree Collapse file tree 2 files changed +23
-0
lines changed Original file line number Diff line number Diff line change 14
14
#include "CheckExprLifetime.h"
15
15
#include "clang/AST/ASTConsumer.h"
16
16
#include "clang/AST/Attr.h"
17
+ #include "clang/AST/DeclCXX.h"
17
18
#include "clang/AST/Expr.h"
18
19
#include "clang/Basic/TargetInfo.h"
19
20
#include "clang/Lex/Preprocessor.h"
@@ -219,6 +220,10 @@ void Sema::inferGslOwnerPointerAttribute(CXXRecordDecl *Record) {
219
220
void Sema::inferLifetimeBoundAttribute(FunctionDecl *FD) {
220
221
if (FD->getNumParams() == 0)
221
222
return;
223
+ // Skip void returning functions (except constructors). This can occur in
224
+ // cases like 'as_const'.
225
+ if (!isa<CXXConstructorDecl>(FD) && FD->getReturnType()->isVoidType())
226
+ return;
222
227
223
228
if (unsigned BuiltinID = FD->getBuiltinID()) {
224
229
// Add lifetime attribute to std::move, std::fowrard et al.
Original file line number Diff line number Diff line change
1
+ // RUN: %clang_cc1 -std=c++20 -Wno-ignored-attributes -Wno-unused-value -verify %s
2
+ // expected-no-diagnostics
3
+ namespace std {
4
+ template <class T>
5
+ constexpr const T& as_const(T&) noexcept;
6
+
7
+ // We need two declarations to see the error for some reason.
8
+ template <class T> void as_const(const T&&) noexcept = delete;
9
+ template <class T> void as_const(const T&&) noexcept;
10
+ }
11
+
12
+ namespace GH126231 {
13
+
14
+ void test() {
15
+ int a = 1;
16
+ std::as_const(a);
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments