diff options
author | Jeffrey Yasskin <jyasskin@google.com> | 2011-01-25 20:08:12 +0000 |
---|---|---|
committer | Jeffrey Yasskin <jyasskin@google.com> | 2011-01-25 20:08:12 +0000 |
commit | c60e13aeff96515d27638129154b1308c15ded3d (patch) | |
tree | f170899d1f2267e8b075786da203ee1633ba29c0 /lib/Sema/SemaExprCXX.cpp | |
parent | 48a4ce7d484a448490edfe9e1d47b806cee85f30 (diff) |
Add an attribute to forbid temporary instances of a type. This allows class
authors to write
class __attribute__((forbid_temporaries)) Name { ... };
when they want to force users to name all variables of the type. This protects
people from doing things like creating a scoped_lock that only lives for a
single statement instead of an entire scope.
The warning produced by this attribute can be disabled by
-Wno-forbid-temporaries.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@124217 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaExprCXX.cpp')
-rw-r--r-- | lib/Sema/SemaExprCXX.cpp | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp index 0b7a051365..cb02be546e 100644 --- a/lib/Sema/SemaExprCXX.cpp +++ b/lib/Sema/SemaExprCXX.cpp @@ -3188,9 +3188,12 @@ ExprResult Sema::MaybeBindToTemporary(Expr *E) { } } + CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); + if (RD->getAttr<ForbidTemporariesAttr>()) + Diag(E->getExprLoc(), diag::warn_temporaries_forbidden) << E->getType(); + // That should be enough to guarantee that this type is complete. // If it has a trivial destructor, we can avoid the extra copy. - CXXRecordDecl *RD = cast<CXXRecordDecl>(RT->getDecl()); if (RD->isInvalidDecl() || RD->hasTrivialDestructor()) return Owned(E); |