From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 051803858422; Wed, 6 Mar 2024 02:05:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 051803858422 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1709690715; bh=Stho/lQ1GBtdARxXFUs8ak4rFFTt8XE1gwgPxxQGqxQ=; h=From:To:Subject:Date:From; b=PEeb5UL4elWaLTVe9QOzHoPIYI4MUl9p9aNudjsiRO0lb0PiFZ+TRxPfaVlhod/8S cd+S22qNzIX7aAtnqTueQ55j86iH6dL4c+yuJQGB9kFd0MqAzkV8bh00r0a2n7kRfF mAqJhEw1yTZQPHdUw9ZyDM3bxEQnb0L6rfJBjxaM= From: "f.heckenbach@fh-soft.de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/114248] New: invalid "scalar object" error Date: Wed, 06 Mar 2024 02:05:13 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: f.heckenbach@fh-soft.de X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D114248 Bug ID: 114248 Summary: invalid "scalar object" error Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: f.heckenbach@fh-soft.de Target Milestone: --- % cat test.cpp=20=20 // #pragma GCC diagnostic ignored "-Wnarrowing" // #pragma GCC diagnostic warning "-Wnarrowing" template struct S { S (int, int) { } }; // template <> using S <-1> =3D int; int main () { S <-1> i { 1, 2 }; } % g++ test.cpp=20 test.cpp: In function 'int main()': test.cpp:13:8: error: narrowing conversion of '-1' from 'int' to 'unsigned = int' [-Wnarrowing] 13 | S <-1> i { 1, 2 }; | ^ test.cpp:13:10: error: scalar object 'i' requires one element in initializer 13 | S <-1> i { 1, 2 }; | ^ The first error is correct, of course, but the second one is not because "i= " is not scalar. Sure, the declaration of "i" is wrong, but this leaves two possible conclusions: - We don't know what "i" is meant to be, so any claim about it is unjustifi= ed. - We see that the type of "i" is meant to be an instance of S which is a struct, and not scalar. AFAIK, even potential specializations of S cannot change this fact (cf. the commented-out line which is doubly wrong). Interestingly, when turning the first error off or into a warning (cf. one = of the commented-out pragmas), the second error disappears as well. I would have expected that those options/pragmas merely control if the narrowing problem is reported, and if so, whether it causes the compilation= to fail, but apparently it does influence gcc's representation of "i" afterwar= ds as well. But that's just a side note actually -- even with a clearly wrong declarati= on of "i" such as S <""> i { 1, 2 }; gcc gives the "scalar" error which it shouldn't.=