From patchwork Tue Jun 19 18:43:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 931803 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-480051-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="QrF9XEWA"; dkim-atps=neutral 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 419H1D4Rq4z9s3M for ; Wed, 20 Jun 2018 04:43:57 +1000 (AEST) 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=HRMGmgJUam6LK0SSiIVuhQeci/zr2wERUvXiwWw2va1cZO +uAm0NbS37leo3/8FEO0nu+eO4aJuciIKjoCW2NWxcbJFn+3+IALw2XHSeszxg3d 7qhKeON3Z4aEWAlHGq9UZgZd2jmxEAhOYSk6PEmqRdEX3mBP4DCncV4W3ZkX4= 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=KOT5kp7eAhxU9R0vUXY2ivDkLUQ=; b=QrF9XEWAjGhVCiQaKtLJ EStm3rJsm3F/D/UBEgN4ufxwGOSM1plDIOvPpBPuv6WcYevyOT4+Oj4r0aulxX4y +OxtcuCDvEZyX3XZpFLi/PtSx/H9SyHQoyj3WV4jJG5js4t8y3TeM/61eykY7wTr aiFnmbWBMYTnDeBGG9vyAqY= Received: (qmail 61494 invoked by alias); 19 Jun 2018 18:43:42 -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 61352 invoked by uid 89); 19 Jun 2018 18:43:40 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.4 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=ux, UD:u.x, sk:DECL_TE, H*r:sk:r18-v6s X-HELO: mail-ot0-f181.google.com Received: from mail-ot0-f181.google.com (HELO mail-ot0-f181.google.com) (74.125.82.181) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 19 Jun 2018 18:43:39 +0000 Received: by mail-ot0-f181.google.com with SMTP id r18-v6so856737otk.1 for ; Tue, 19 Jun 2018 11:43:39 -0700 (PDT) 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=fkbOQSXdssUChJIPSGrKcTOf0k/QA1v9ZEYrxLV5yxs=; b=QJ/aYPwOBszPchV4PkN5p9HszSEEQxfE/XDU0PBNk4YIUyYhWXRnc4QCFtKD4rdGwb 3gpKMQGuxvNZ85XiZoGONyTh7OvMdBqhnoO0jUYarWOWi8lxwtB+Yw8GClwbBuM/MQjz KUSBLk5rwzOEzOlBPpJa0//XBjEAMbS/bnU33+in6ocIP3JGFukQ9lTlZZ9AfnfefgM8 CmW0xBuVe//svCLRskWwbzfIGwcBMkwZ4WawipPDl5UAguIUanRvDAsY1ClgEmbZnlrr Yw90EwAI8HXkiXtOqzfUvKaFfxHVCXDS/JJ/TIOaEQVG2MM84tfi0aTXWGSKZS2FXyD1 mncQ== X-Gm-Message-State: APt69E1pxK9kkIw0GYn0L8eSWVPLVzO1uybUyT1MYvGXxY6kwENxb3pd FOWxrC527uDgWRbrYjOoPbCkAXRL8SlZcl+79GJmClHU X-Google-Smtp-Source: ADUXVKKi5EAj2lzZ6C6YcmKKoJ5C+6k+iRcS+MHpwJHbBlEI0a38w8oAL4NrmJ3mn7k42Hk9gXrV3OEwcnChnzUMqcg= X-Received: by 2002:a9d:caf:: with SMTP id b44-v6mr10445380otb.270.1529433817205; Tue, 19 Jun 2018 11:43:37 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:ac9:dd0:0:0:0:0:0 with HTTP; Tue, 19 Jun 2018 11:43:16 -0700 (PDT) From: Jason Merrill Date: Tue, 19 Jun 2018 14:43:16 -0400 Message-ID: Subject: C++ PATCH for c++/86192, ICE with template argument of anonymous union type To: gcc-patches List X-IsSubscribed: yes Someone found a sneaky way to use an anonymous union type as a template argument. That seems to me like it ought to be ill-formed, but this patch is a simple enough way to make this testcase work. Tested x86_64-pc-linux-gnu, applying to trunk. commit 4f51a88ed61f69fd483a46b93f0ba9cff352324a Author: Jason Merrill Date: Mon Jun 18 21:20:29 2018 -0400 PR c++/86192 - ICE with anonymous union passed to template. * pt.c (tsubst_expr) [DECL_EXPR]: Handle an anonymous union type used to declare a named variable. diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 1ecc6fb373d..3386385b3f8 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -16678,7 +16678,7 @@ tsubst_expr (tree t, tree args, tsubst_flags_t complain, tree in_decl, do. */ if (VAR_P (decl)) DECL_TEMPLATE_INSTANTIATED (decl) = 1; - if (VAR_P (decl) + if (VAR_P (decl) && !DECL_NAME (decl) && ANON_AGGR_TYPE_P (TREE_TYPE (decl))) /* Anonymous aggregates are a special case. */ finish_anon_union (decl); diff --git a/gcc/testsuite/g++.dg/template/anonunion3.C b/gcc/testsuite/g++.dg/template/anonunion3.C new file mode 100644 index 00000000000..1ac8165fa78 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/anonunion3.C @@ -0,0 +1,16 @@ +// PR c++/86192 +// { dg-do compile { target c++11 } } + +extern "C" int printf (const char *, ...); + +template static char const * f(T *t) { + T u(*t); + u.x = "hello world"; + printf("%s\n", u.x); + return "initialized"; +} + +int main() { + union { char const *x = f(this); }; + printf("%s\n", x); +}