From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 130079 invoked by alias); 4 Feb 2018 17:09:23 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 130061 invoked by uid 89); 4 Feb 2018 17:09:23 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,KAM_SHORT,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=H*f:sk:1b58e2d, H*i:sk:1b58e2d, quality, authority X-HELO: mail-wm0-f51.google.com Received: from mail-wm0-f51.google.com (HELO mail-wm0-f51.google.com) (74.125.82.51) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 04 Feb 2018 17:09:21 +0000 Received: by mail-wm0-f51.google.com with SMTP id f3so21543976wmc.1 for ; Sun, 04 Feb 2018 09:09:20 -0800 (PST) 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=rRDBdEtNj2fYsRqYT/vf5zHhtSktiRRksBg4p9DaDvs=; b=tZjDomte/lPOjHbunUqRb61NUE/0RVUt3ZJi+1XLEFKi0qXxeI6JR0aC9S2v/JFCkk nbB/BIGZ0qJAIKELNQ6Ldi/+0m7JbNAnbV54akweDF/YFeJ4zpCIijn/gkWpfOOCs7QE UPLbDlWOLBqDr7Hsftrl8HiGWsJZUjblb0v5yx5BZjYbQHKyPOR/A8jkPy5p0HexZ+R/ btuW/MYfneozszDwhu12iKlsaOO6xA8grzyvP5d7ax9rGErMKmQkZKJTe6SPwhFZV4mU VU45gR+Fyv1Xum7DGN8Yu01j9h/YPr+PA7xk8PDqJlfVYpvsqpFrKbVb7xbWiB6iBCFM 57wQ== X-Gm-Message-State: AKwxytdb6clABiGnkqiMcDlN2o/PNclbv8wDnY3aUdEinOxQI0g33ZfL MlLNPRKRD2TliPGp63zq+dLTrQ== X-Google-Smtp-Source: AH8x226hf/4bmlyVZhu5rWeDwknM8jkS0ewSoPy5hYNdDbe/XNlc/FAmMjcyxkL5Mem5j11JHTH4OA== X-Received: by 10.28.7.68 with SMTP id 65mr32959774wmh.9.1517764158924; Sun, 04 Feb 2018 09:09:18 -0800 (PST) Received: from [192.168.0.169] ([151.58.14.242]) by smtp.googlemail.com with ESMTPSA id q195sm7740207wmb.33.2018.02.04.09.09.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 04 Feb 2018 09:09:18 -0800 (PST) Subject: Re: gdb 8.x - g++ 7.x compatibility To: gdb@sourceware.org, gcc@gcc.gnu.org References: <1517667601.3405.123.camel@gnu.org> <1b58e2df-5425-4f22-510c-d2e9f51040ba@polymtl.ca> From: Manfred Message-ID: <04f1a58f-b87f-78e7-366f-47e1c0933319@gmail.com> Date: Sun, 04 Feb 2018 17:09:00 -0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.6.0 MIME-Version: 1.0 In-Reply-To: <1b58e2df-5425-4f22-510c-d2e9f51040ba@polymtl.ca> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-IsSubscribed: yes X-SW-Source: 2018-02/txt/msg00017.txt.bz2 On 2/4/2018 6:01 AM, Simon Marchi wrote: > On 2018-02-03 13:35, Manfred wrote: >> n4659 17.4 (Type equivalence) p1.3: >> >> Two template-ids refer to the same class, function, or variable if >> ... >> their corresponding non-type template arguments of integral or >> enumeration type have identical values >> ... >> >> It looks that for non-type template arguments the template type >> equivalence is based on argument /value/ not /type/ (and value), so >> IMHO gcc is correct where it considers foo<10u> and foo<10> to be the >> same type, i.e. "refer to the same class" >> >> FWIW, type_info reports the same class name for both templates, which >> appears to be correct as per the above. >> >> I would think someone from gcc might be more specific on why both >> templates print 4294967286, and what debug info is actually stored by >> -g in this case. > > I think that Roman's example clearly shows that they are not equivalent in > all cases. I was merely reporting the wording of the standard, which would be the authority to follow. I may agree that not specifying type identity may lead to unexpected results. Personally I would prefer the standard to say "identical value and type" here (and it appears from your findings below that quality compilers already handle it this way), but this is only an opinion. > > Building Roman's example with g++ 7.3 results in a single instantiated type. You > can see that both "new foo<10>()" and "new foo<10u>()" end up calling the same > constructor. It seems like which type is instantiated depends on which template > parameter (the signed or unsigned one) you use first. So with this: > > base * fi = new foo<10>(); > base * fu = new foo<10u>(); > > the output is -10 for both, and with > > base * fu = new foo<10u>(); > base * fi = new foo<10>(); > > the output is 4294967286 for both. But it's probably a bogus behavior. Indeed. I tested > with clangd, it instantiates two different types, so you get 4294967286 for the > <10u> case and -10 for the <10> case. I also just built gcc from master, and it > also instantiates two types, so it seems like that was fixed recently. > > So let's see what debug info gcc master generates for these two instances of foo > (clang master generates the equivalent). > > <1><9257>: Abbrev Number: 66 (DW_TAG_structure_type) > <9258> DW_AT_name : (indirect string, offset: 0x8455): foo<10> > <925c> DW_AT_byte_size : 16 > <925d> DW_AT_decl_file : 1 > <925e> DW_AT_decl_line : 7 > <925f> DW_AT_decl_column : 8 > <9260> DW_AT_containing_type: <0x92fd> > <9264> DW_AT_sibling : <0x92f8> > ... > <1><93be>: Abbrev Number: 66 (DW_TAG_structure_type) > <93bf> DW_AT_name : (indirect string, offset: 0x8455): foo<10> > <93c3> DW_AT_byte_size : 16 > <93c4> DW_AT_decl_file : 1 > <93c5> DW_AT_decl_line : 7 > <93c6> DW_AT_decl_column : 8 > <93c7> DW_AT_containing_type: <0x92fd> > <93cb> DW_AT_sibling : <0x945f> > > If there are two types with the same name, how is gdb expected to differentiate > them? > > If we can't rely on the DW_AT_name anymore to differentiate templated types, then > the only alternative I see would be to make GDB ignore the template part of the > DW_AT_name value, and reconstruct it in the format it expects (with the u) from the > DW_TAG_template_value_param DIEs children of DW_TAG_structure_type (there's already > code to do that in dwarf2_compute_name). Their types correctly point to the signed > int or unsigned int DIE, so we have the necessary information. However, that would > mean reading many more full DIEs early on, when just building partial symbols, which > would slow done loading the symbols of pretty much any C++ program. > > From what I understand from the original change that caused all this [1], removing > the suffixes was meant to make the error messages more readable for the user. > However, since foo<10>::print() and foo<10u>::print() are not the same function, > I think it would actually be more confusing if an error message talked about the > instantiation with the unsigned type, but mentioned "foo<10>::print()". For example, > if you put a > > static_assert (std::is_signed::value); > > in the print method, this is the error message from gcc: > > test.cpp: In instantiation of 'void foo::print() [with auto IVAL = 10]': > test.cpp:24:1: required from here > test.cpp:12:22: error: static assertion failed > static_assert (std::is_signed::value); > ^~~ > > Wouldn't the message make more sense with a u suffix? Probably so. > > Simon > > [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78165 >