diff options
-rw-r--r-- | gcc/cp/tree.cc | 30 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C | 20 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/template/non-dependent23.C | 25 |
3 files changed, 68 insertions, 7 deletions
diff --git a/gcc/cp/tree.cc b/gcc/cp/tree.cc index ed0d0d22950..3b37567cbd7 100644 --- a/gcc/cp/tree.cc +++ b/gcc/cp/tree.cc @@ -4318,15 +4318,31 @@ maybe_dummy_object (tree type, tree* binfop) if (binfop) *binfop = binfo; - if (current_class_ref - /* current_class_ref might not correspond to current_class_type if - we're in tsubst_default_argument or a lambda-declarator; in either - case, we want to use current_class_ref if it matches CONTEXT. */ - && (same_type_ignoring_top_level_qualifiers_p - (TREE_TYPE (current_class_ref), context))) + /* current_class_ref might not correspond to current_class_type if + we're in tsubst_default_argument or a lambda-declarator; in either + case, we want to use current_class_ref if it matches CONTEXT. */ + tree ctype = current_class_ref ? TREE_TYPE (current_class_ref) : NULL_TREE; + if (ctype + && same_type_ignoring_top_level_qualifiers_p (ctype, context)) decl = current_class_ref; else - decl = build_dummy_object (context); + { + /* Return a dummy object whose cv-quals are consistent with (the + non-lambda) 'this' if available. */ + if (ctype) + { + int quals = TYPE_UNQUALIFIED; + if (tree lambda = CLASSTYPE_LAMBDA_EXPR (ctype)) + { + if (tree cap = lambda_expr_this_capture (lambda, false)) + quals = cp_type_quals (TREE_TYPE (TREE_TYPE (cap))); + } + else + quals = cp_type_quals (ctype); + context = cp_build_qualified_type (context, quals); + } + decl = build_dummy_object (context); + } return decl; } diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C new file mode 100644 index 00000000000..8c6afe06cac --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-this22.C @@ -0,0 +1,20 @@ +// PR c++/105637 +// { dg-do compile { target c++11 } } + +struct Base { + void foo(); // #1 + void foo() const = delete; // #2 +}; + +template<class T> +struct TopClass : T { + void failsToCompile() { + [this] { Base::foo(); }(); // should select #2, not #1 + } + + void failsToCompile() const { + [this] { Base::foo(); }(); // { dg-error "deleted" } + } +}; + +template struct TopClass<Base>; diff --git a/gcc/testsuite/g++.dg/template/non-dependent23.C b/gcc/testsuite/g++.dg/template/non-dependent23.C new file mode 100644 index 00000000000..885a641a655 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/non-dependent23.C @@ -0,0 +1,25 @@ +// PR c++/105637 + +struct Base { + void foo(); // #1 + void foo() const; // #2 + void foo() volatile; // #3 + void foo() const volatile; // #4 +}; + +template<class T> +struct TopClass : T { + void failsToCompile() const { + Base::foo(); // should select #2, not #1 + } + + void failsToCompile() volatile { + Base::foo(); // should select #3, not #1 + } + + void failsToCompile() const volatile { + Base::foo(); // should select #4, not #1 + } +}; + +template struct TopClass<Base>; |