From patchwork Wed Jan 18 21:04:08 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 716840 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3v3fcG6K5hz9t23 for ; Thu, 19 Jan 2017 08:04:46 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="mIqjBAah"; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; q= dns; s=default; b=ToyczVXkHA9uehrfWfx/8+61LGyQuFg39DODvizP5RDQ8v +hhp7fSG3pBsoBfyBaYoB5Q8nkwCKwKh2diMx5tsiIPfgCa9bG5Usx1ECWNRmxhg eR1Rr/kdMd1ALqHUT+G9yXlbhGbSpdVrwRvetEAPukHXMakF03CkN1zj1tEo0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender :mime-version:from:date:message-id:subject:to:content-type; s= default; bh=TYVy6PBxEkRw0lZ/bWsTExP6rAY=; b=mIqjBAahumazraxXzmwh LTGmNA43Sua7pAV3BkxteAe8nuin6zi1z0LU++iCy7s2PP8WdzOSCOwR4VRzzmAn U+AUh7aYzJ+zYHWF260eXcGSNbphqJ55HLZ9FqjIJdyWh0uzxAK7PUuwWqIJZaCw 4HO7F4jrVbpoUeuKa0lNiZo= Received: (qmail 111785 invoked by alias); 18 Jan 2017 21:04:33 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 111775 invoked by uid 89); 18 Jan 2017 21:04:32 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.2 spammy=ay, H*F:U*jason, tsubst_flags_t, tf_error X-HELO: mail-ot0-f174.google.com Received: from mail-ot0-f174.google.com (HELO mail-ot0-f174.google.com) (74.125.82.174) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 18 Jan 2017 21:04:31 +0000 Received: by mail-ot0-f174.google.com with SMTP id 104so17817446otd.3 for ; Wed, 18 Jan 2017 13:04:31 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=t9AJ/l5rfG4CO01BJIf3+wvps34QArxURXAXERsreLo=; b=QvOpHxn6vyWu4li5zRQlxnbdqjWWTWPFulcok2lq6z2VBsivtCIbW3h2zfAKkJmsj4 vtryva0IKnAtlxIH727qefYEjpBqETSHbcczr5vmcIOcFCh6kNv+lc9K84csJvot+lRA WWm+Szt7giuIVa0e+ATCRgZPrMfQRQNAacXUXx47WzGq3BBBy26ydwFFCw+6W7it6gl1 9QZ8MAe4oo0STv9kkQWC35hVKRXrCszoANOGLy3Hdz2/lCilUJusr4SKxVViRhu7uy8Q SF1xalm9Uy9U00XZeBj7Rztlo5UGgfqTrhzm1JYMxOqvLy6MH+vJvT9R5VKMh8Ez6WNn hILw== X-Gm-Message-State: AIkVDXKWnNjn7ErqxgOmaBZKkyR6bLUhmUYAJHLmoOlz2vp1kNDJjSjNF/UA+/I8pdY3jYO4cQjLlx/8R+U8Aa4z X-Received: by 10.157.19.43 with SMTP id f40mr2900607ote.189.1484773469683; Wed, 18 Jan 2017 13:04:29 -0800 (PST) MIME-Version: 1.0 Received: by 10.182.173.104 with HTTP; Wed, 18 Jan 2017 13:04:08 -0800 (PST) From: Jason Merrill Date: Wed, 18 Jan 2017 16:04:08 -0500 Message-ID: Subject: C++ PATCH for c++/68666 (member variable template) To: gcc-patches List X-IsSubscribed: yes The problem was that finish_class_member_access_expr got missed when we added variable templates. 68666 is a report of how this affects concepts; the patch adds both concepts and non-concepts testcases. Tested x86_64-pc-linux-gnu, applying to trunk. commit 40ab19fcedf621438a819dbdf08d9ee66e3143db Author: Jason Merrill Date: Wed Jan 18 15:16:47 2017 -0500 PR c++/68666 - member variable template-id * typeck.c (finish_class_member_access_expr): Handle variable template-id. * pt.c (lookup_and_finish_template_variable): No longer static. * cp-tree.h: Declare it. diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index 98e4cbd..9c44367 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -6449,6 +6449,7 @@ extern cp_expr perform_koenig_lookup (cp_expr, vec *, tsubst_flags_t); extern tree finish_call_expr (tree, vec **, bool, bool, tsubst_flags_t); +extern tree lookup_and_finish_template_variable (tree, tree, tsubst_flags_t = tf_warning_or_error); extern tree finish_template_variable (tree, tsubst_flags_t = tf_warning_or_error); extern cp_expr finish_increment_expr (cp_expr, enum tree_code); extern tree finish_this_expr (void); diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 6fd03a5..c679133 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9035,7 +9035,7 @@ finish_template_variable (tree var, tsubst_flags_t complain) /* Construct a TEMPLATE_ID_EXPR for the given variable template TEMPL having TARGS template args, and instantiate it if it's not dependent. */ -static tree +tree lookup_and_finish_template_variable (tree templ, tree targs, tsubst_flags_t complain) { diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index b84f8bee..579c580 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -2875,7 +2875,10 @@ finish_class_member_access_expr (cp_expr object, tree name, bool template_p, tree templ = member; if (BASELINK_P (templ)) - templ = lookup_template_function (templ, template_args); + member = lookup_template_function (templ, template_args); + else if (variable_template_p (templ)) + member = (lookup_and_finish_template_variable + (templ, template_args, complain)); else { if (complain & tf_error) diff --git a/gcc/testsuite/g++.dg/concepts/var-templ3.C b/gcc/testsuite/g++.dg/concepts/var-templ3.C new file mode 100644 index 0000000..b882b08 --- /dev/null +++ b/gcc/testsuite/g++.dg/concepts/var-templ3.C @@ -0,0 +1,12 @@ +// PR c++/68666 +// { dg-options "-std=c++1z -fconcepts" } + +struct A { + template + static constexpr bool val = true; +}; + +template +concept bool C = A::val; + +C{T} struct B {}; diff --git a/gcc/testsuite/g++.dg/cpp1y/var-templ55.C b/gcc/testsuite/g++.dg/cpp1y/var-templ55.C new file mode 100644 index 0000000..0840df3 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/var-templ55.C @@ -0,0 +1,12 @@ +// { dg-do compile { target c++14 } } + +template struct A { + template static const U x = 1; + static const int y = 2; +}; + +int main() { + A a; + int y = a.y; // OK + int x = a.x; // ??? +}