From patchwork Mon Oct 9 19:20:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mukesh Kapoor X-Patchwork-Id: 823437 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-463800-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="DjTYOovS"; 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 3y9qnz09kxz9t44 for ; Tue, 10 Oct 2017 06:20:22 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=yzgSXqpIfCroexJrMj9vFoQA3aCesez4Lxx3O5c94EjX0aGEfF u8uyXGRWUvj/0jkK2dg2Gvu/jMQXuf0GjCAaTbgZMkZ9nkeDKSURuTQ34MnvD+Zd LOoqKEHybJu2wNp+Yiolhp80GOnD7X93X0MW/OBKDqAx8DTgUylK3GG1Y= 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:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=zXaw3vJHpQkS+DdsX49u4u94w8Y=; b=DjTYOovSWGtRwIe5GXDQ s4M2sN52CxvaYw7n5OiWKee7XaeALq2asJJMK1TLInTKM2VDKdoBR6kRYznCdL8j sDnc/9d0Sw9ZmxnJQ6oxm3HY8nVQEw7e6+iN+h/STtjVRR9eD9g3uEs1lTW+7k7U PlMVX/Q3dA6xSRRcqQgNfcc= Received: (qmail 37510 invoked by alias); 9 Oct 2017 19:20:16 -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 37500 invoked by uid 89); 9 Oct 2017 19:20:15 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RP_MATCHES_RCVD, SPF_PASS autolearn=ham version=3.3.2 spammy=H*MI:1554, H*M:1554 X-HELO: aserp1040.oracle.com Received: from aserp1040.oracle.com (HELO aserp1040.oracle.com) (141.146.126.69) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 09 Oct 2017 19:20:14 +0000 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v99JKAlw007735 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Oct 2017 19:20:11 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v99JKAQe023010 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 9 Oct 2017 19:20:10 GMT Received: from abhmp0010.oracle.com (abhmp0010.oracle.com [141.146.116.16]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v99JKAP6008561; Mon, 9 Oct 2017 19:20:10 GMT Received: from [10.159.243.180] (/10.159.243.180) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 09 Oct 2017 12:20:09 -0700 To: gcc-patches@gcc.gnu.org Cc: nathan@acm.org From: Mukesh Kapoor Subject: [C++ Patch] PR 82307 Message-ID: <906899ba-66bc-a8c7-1554-5c3b1a330098@oracle.com> Date: Mon, 9 Oct 2017 12:20:52 -0700 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 Hi, This patch fixes https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82307. For an unscoped enum with a fixed underlying type, the function type_promotes_to() does not always return the same type as the underlying type. The fix is to use the underlying type of the enum instead of creating a new one by calling c_common_type_for_size(). Bootstrapped and tested with 'make check' on x86_64-linux. New test case added. Mukesh Index: gcc/cp/cvt.c =================================================================== --- gcc/cp/cvt.c (revision 253551) +++ gcc/cp/cvt.c (working copy) @@ -1854,11 +1854,16 @@ tree prom = type; if (TREE_CODE (prom) == ENUMERAL_TYPE) prom = ENUM_UNDERLYING_TYPE (prom); - if (TYPE_UNSIGNED (prom) - && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype)) - prom = c_common_type_for_size (precision, 1); - else - prom = totype; + // If an unscoped enum has fixed underlying type, + // use that type (bug 82307) + if (!ENUM_FIXED_UNDERLYING_TYPE_P (type) || SCOPED_ENUM_P (type)) + { + if (TYPE_UNSIGNED (prom) + && ! int_fits_type_p (TYPE_MAX_VALUE (prom), totype)) + prom = c_common_type_for_size (precision, 1); + else + prom = totype; + } if (SCOPED_ENUM_P (type)) { if (abi_version_crosses (6) Index: gcc/testsuite/g++.dg/cpp0x/pr_82307.C =================================================================== --- gcc/testsuite/g++.dg/cpp0x/pr_82307.C (revision 0) +++ gcc/testsuite/g++.dg/cpp0x/pr_82307.C (working copy) @@ -0,0 +1,24 @@ +// PR c++/82307 +// { dg-do compile { target c++11 } } + +#include +#include + +enum : unsigned long long { VAL }; + +const char* foo( unsigned long long ) +{ + return "unsigned long long"; +} + +const char* foo( int ) +{ + return "int"; +} + +int main( void ) +{ + if (strcmp(foo(VAL), "unsigned long long") != 0) + abort(); +} +