diff options
author | Richard Trieu <rtrieu@google.com> | 2011-09-01 21:44:13 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2011-09-01 21:44:13 +0000 |
commit | 898267f67b8131c4bed4430e2cfaf69ccf4c2de1 (patch) | |
tree | ee10d2cb647f89142098d43ee40a9466392e894f /lib/Sema/SemaInit.cpp | |
parent | aec230d29835285777ecc467e268c83b33a2adde (diff) |
Extend the self-reference warning to catch when a constructor references itself upon initialization, such as using itself within its own copy constructor.
struct S {};
S s(s);
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@138969 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaInit.cpp')
-rw-r--r-- | lib/Sema/SemaInit.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/lib/Sema/SemaInit.cpp b/lib/Sema/SemaInit.cpp index 06d530f007..bcdd4801ab 100644 --- a/lib/Sema/SemaInit.cpp +++ b/lib/Sema/SemaInit.cpp @@ -3078,6 +3078,14 @@ static void TryConstructorInitialization(Sema &S, Expr **Args, unsigned NumArgs, QualType DestType, InitializationSequence &Sequence) { + // Check constructor arguments for self reference. + if (DeclaratorDecl *DD = Entity.getDecl()) + // Parameters arguments are occassionially constructed with itself, + // for instance, in recursive functions. Skip them. + if (!isa<ParmVarDecl>(DD)) + for (unsigned i = 0; i < NumArgs; ++i) + S.CheckSelfReference(DD, Args[i]); + // Build the candidate set directly in the initialization sequence // structure, so that it will persist if we fail. OverloadCandidateSet &CandidateSet = Sequence.getFailedCandidateSet(); |