Skip to content

Commit

Permalink
[clang] fixing conditional explicit for out-of-line definition PR42980
Browse files Browse the repository at this point in the history
Summary: not every read in CXXConstructorDecl::getExplicitSpecifierInternal() was made on the canonical declaration.

Reviewers: rsmith, aaron.ballman

Reviewed By: rsmith

Subscribers: cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D67889

llvm-svn: 372530
  • Loading branch information
Ralender committed Sep 22, 2019
1 parent 638933a commit 914c4c3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
8 changes: 4 additions & 4 deletions clang/include/clang/AST/DeclCXX.h
Original file line number Diff line number Diff line change
Expand Up @@ -2555,9 +2555,9 @@ class CXXConstructorDecl final

ExplicitSpecifier getExplicitSpecifierInternal() const {
if (CXXConstructorDeclBits.HasTrailingExplicitSpecifier)
return *getCanonicalDecl()->getTrailingObjects<ExplicitSpecifier>();
return *getTrailingObjects<ExplicitSpecifier>();
return ExplicitSpecifier(
nullptr, getCanonicalDecl()->CXXConstructorDeclBits.IsSimpleExplicit
nullptr, CXXConstructorDeclBits.IsSimpleExplicit
? ExplicitSpecKind::ResolvedTrue
: ExplicitSpecKind::ResolvedFalse);
}
Expand Down Expand Up @@ -2598,10 +2598,10 @@ class CXXConstructorDecl final
InheritedConstructor Inherited = InheritedConstructor());

ExplicitSpecifier getExplicitSpecifier() {
return getExplicitSpecifierInternal();
return getCanonicalDecl()->getExplicitSpecifierInternal();
}
const ExplicitSpecifier getExplicitSpecifier() const {
return getExplicitSpecifierInternal();
return getCanonicalDecl()->getExplicitSpecifierInternal();
}

/// Return true if the declartion is already resolved to be explicit.
Expand Down
18 changes: 18 additions & 0 deletions clang/test/SemaCXX/cxx2a-explicit-bool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,3 +717,21 @@ A d2{0, 0};
A d3 = {0.0, 0.0};// expected-error {{explicit deduction guide}}

}

namespace PR42980 {
using size_t = decltype(sizeof(0));

struct Str {// expected-note+ {{candidate constructor}}
template <size_t N>
explicit(N > 7)// expected-note {{resolved to true}}
Str(char const (&str)[N]);
};

template <size_t N>
Str::Str(char const(&str)[N]) { }
// expected-note@-1 {{candidate constructor}}

Str a = "short";
Str b = "not so short";// expected-error {{no viable conversion}}

}

0 comments on commit 914c4c3

Please sign in to comment.