From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id BEDF33861024 for ; Wed, 28 Oct 2020 19:19:50 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BEDF33861024 Received: from mail-il1-f197.google.com (mail-il1-f197.google.com [209.85.166.197]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-460-dfbuAQMcOGqIdlGA7F0bjw-1; Wed, 28 Oct 2020 15:19:47 -0400 X-MC-Unique: dfbuAQMcOGqIdlGA7F0bjw-1 Received: by mail-il1-f197.google.com with SMTP id t6so239372ilj.10 for ; Wed, 28 Oct 2020 12:19:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=UCLeFg/VkoYkBQTzGBMLbue4b9Z2Z32SXhU9ti+vtRc=; b=rF1nAtlUhIUFkGGqVq6PSZkLxDGxZL7ak2ZyDBwNUO1KpQWwZGVEVVIadRX0TdhuM5 cll6jZZT7ZLs/cM5Q4uVD5NfyFyUEQZcW1bLAb2yMhWGoUc1W8i2Ejol+DxJcqr9c3GE A0FuLqiKw9Z1RMh7wZrvikgDkDiHnnC7bHtJNYq6g738W6Gt2fRU5iLhxYrQ5MM/1QEA 1S5THyFhZwmih3vW+3qVb8VgDHFPQnRrULdbMdZ+9KYGhL7Z+s99F/ZHeAARThJYTPaZ 1EC6CvcjpbwvW8fwCOPsSxDFydYk0zjL8VGMBpMCwOqqzf3dTMcOdRFnUkYg/3mZ8Aay mBnQ== X-Gm-Message-State: AOAM533dVVuS/PZUjjzEgoP9+gS7o8eeK6OMZV/ULzAGOn4bQ7xhXIB4 3DScGr2U0NX1bBdsbz2qJo5BC1vOcIw48lRzTYPe7e1o8o5AIgyE55mQT4owt4XD75DxVAXnClG rjoDG4KCdDvpag7LK+g== X-Received: by 2002:a05:6638:1182:: with SMTP id f2mr600234jas.73.1603912786214; Wed, 28 Oct 2020 12:19:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxr7naQwWp36jPiH2dyq3lpqhZvVG5gFeHuXvXcYUCVANhxLPw6uqQqBs15BhEYx8VC4oQc5A== X-Received: by 2002:a05:6638:1182:: with SMTP id f2mr600214jas.73.1603912785895; Wed, 28 Oct 2020 12:19:45 -0700 (PDT) Received: from [192.168.1.148] (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id r77sm147121iod.49.2020.10.28.12.19.44 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 28 Oct 2020 12:19:45 -0700 (PDT) Subject: Re: [PATCH] c++: Member template function lookup failure [PR94799] To: Marek Polacek , GCC Patches References: <20201020005202.64863-1-polacek@redhat.com> From: Jason Merrill Message-ID: <0812fd9e-b620-f229-6fda-c4b976c92323@redhat.com> Date: Wed, 28 Oct 2020 15:19:44 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: <20201020005202.64863-1-polacek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-17.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 28 Oct 2020 19:19:52 -0000 On 10/19/20 8:52 PM, Marek Polacek wrote: > My earlier patch for this PR, r11-86, broke pybind11. That patch > changed cp_parser_class_name to also consider the object expression > scope (parser->context->object_type) to fix parsing of > > p->template A::foo(); // consider p's scope too > > Here we reject > > b.operator typename B::type(); > > because 'typename_p' in cp_parser_class_name uses 'scope', which means > that 'typename_p' will be true for the example above. Then we create > a TYPENAME_TYPE via make_typename_type, which fails when tsubsting it; > the code basically created 'typename B::B' and then we complain that there > is no member named 'B' in 'A'. So, when deciding if we should > create a TYPENAME_TYPE, don't consider the object_type scope, like we > did pre-r11-86. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? OK. > gcc/cp/ChangeLog: > > PR c++/94799 > * parser.c (cp_parser_class_name): Use parser->scope when > setting typename_p. > > gcc/testsuite/ChangeLog: > > PR c++/94799 > * g++.dg/template/lookup16.C: New test. > --- > gcc/cp/parser.c | 13 ++++++------- > gcc/testsuite/g++.dg/template/lookup16.C | 23 +++++++++++++++++++++++ > 2 files changed, 29 insertions(+), 7 deletions(-) > create mode 100644 gcc/testsuite/g++.dg/template/lookup16.C > > diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c > index 7ec7d42773c..ecbd4b7d15a 100644 > --- a/gcc/cp/parser.c > +++ b/gcc/cp/parser.c > @@ -23784,13 +23784,10 @@ cp_parser_class_name (cp_parser *parser, > bool enum_ok) > { > tree decl; > - tree scope; > - bool typename_p; > - cp_token *token; > tree identifier = NULL_TREE; > > /* All class-names start with an identifier. */ > - token = cp_lexer_peek_token (parser->lexer); > + cp_token *token = cp_lexer_peek_token (parser->lexer); > if (token->type != CPP_NAME && token->type != CPP_TEMPLATE_ID) > { > cp_parser_error (parser, "expected class-name"); > @@ -23806,14 +23803,16 @@ cp_parser_class_name (cp_parser *parser, > > where we first want to look up A::a in the class of the object > expression, as per [basic.lookup.classref]. */ > - scope = parser->scope ? parser->scope : parser->context->object_type; > + tree scope = parser->scope ? parser->scope : parser->context->object_type; > if (scope == error_mark_node) > return error_mark_node; > > /* Any name names a type if we're following the `typename' keyword > in a qualified name where the enclosing scope is type-dependent. */ > - typename_p = (typename_keyword_p && scope && TYPE_P (scope) > - && dependent_type_p (scope)); > + const bool typename_p = (typename_keyword_p > + && parser->scope > + && TYPE_P (parser->scope) > + && dependent_type_p (parser->scope)); > /* Handle the common case (an identifier, but not a template-id) > efficiently. */ > if (token->type == CPP_NAME > diff --git a/gcc/testsuite/g++.dg/template/lookup16.C b/gcc/testsuite/g++.dg/template/lookup16.C > new file mode 100644 > index 00000000000..5b34c08282c > --- /dev/null > +++ b/gcc/testsuite/g++.dg/template/lookup16.C > @@ -0,0 +1,23 @@ > +// PR c++/94799 > +// { dg-do compile { target c++11 } } > + > +template struct A { > + typedef int type; > + operator int(); > +}; > + > +template using B = A; > + > +template typename B::type foo(B b) > +{ > + auto r1 = b.operator typename A::type(); > + auto r2 = b.operator typename A::template A::type(); > + auto r3 = b.operator typename B::type(); > + auto r4 = b.operator typename B::template A::type(); > + return r1 + r2 + r3 + r4; > +} > + > +void bar() > +{ > + foo(A()); > +} > > base-commit: 970d683f67777319990b30302a21a860990e2ec8 >