From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 417BA3882052 for ; Thu, 13 Jun 2024 14:42:30 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 417BA3882052 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 417BA3882052 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718289751; cv=none; b=oZ2h/1UCh1xQVBm7cONcW/QJpESTrvxKehtLiMLF2cufZXgODaTWnSmOoyir2mqm8KFYN47dCnZHYRYRt4V7GexZmSX3gie0jPkHB6u/yUHja7+JlOumirPtiwQ2WzDNdpwknbjIp/Qe0y475apoLVVFx1IVGC0MdcinZRB0iDg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718289751; c=relaxed/simple; bh=YFrNrioSI/2/v+uQgSi+tMI9SAy0H2KyIAfCrCOX2EM=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=wviNHX4x20f5JnWJkz7ZyFx/fbS8JYZ55T0KmswoKNn2SSQkaAYVam9PIgDnxWJG8AlDaXeMXPCENn/3eCuNUlkQre/RQYGrtWZk4att7yUTVG58M/ifXL0PCmgcLIp/0rSJgg6XUofSGT7Ds9sJU9m0JM7gMaILp1sZ7Ag7EFw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718289749; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aBDYXz6Tx2iFVbzy1UQEtB2icfwvkEscxXDWA/Ki+RY=; b=fYekUApWiMUWwXkSu1jcKBeq6pafAsd4Q3/OH6z8X/BpSOCg7mPcMt/57u8ytS8czCoAQa 8N1brb66fyLAvxv1r6RGt8oRU7y3ZtpzNOxL6VCvSnFbXrAJhHUeEhpqCLGqbloaw9wPB8 QOvLv3Is8gpzS8+RWWH7DCTw73rpjw0= Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-452-rRcBVxzcMle7hyXy5-bVPg-1; Thu, 13 Jun 2024 10:42:28 -0400 X-MC-Unique: rRcBVxzcMle7hyXy5-bVPg-1 Received: by mail-qk1-f198.google.com with SMTP id af79cd13be357-797f788afa8so173403785a.0 for ; Thu, 13 Jun 2024 07:42:28 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718289748; x=1718894548; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=aBDYXz6Tx2iFVbzy1UQEtB2icfwvkEscxXDWA/Ki+RY=; b=jcUbveH7GsBvw1QpSe3LyByPcJwM1noNzA5Tgy1/qlRgtmTZEg1JOROUlmN4DuKDlG SbhTCI0zijjQzvfKPwY5QCky4qpDfTARf4FO3qqaiaaDuDWz2QiC28WYYk6cOYrfFb+b A5yRlzyvfJ40Q79k59NAF4awAcip6oze+Vk/q3/2OeYzZK4BxLTSABSCkQk4BU0vyMf/ 7AE6y3jT6Cem+2TGHDESdbablqFux2LlWu8BnxvHNhKCX/iCaG0hurncMKUphysUATsS vR2UKoCQDYsqd5uc2/X29tvtfunBv7e7gfGibWbZJuxMvB1bntfP4s1KL5pJiOGumWcX 9Hhw== X-Forwarded-Encrypted: i=1; AJvYcCUZ/wpzDQc3grVrPhIbPnSN9pqM0+MqKlOOJDT7f9381KsOpk8aN26TpGWHy749yNFiDCn/EgCaNjsMY8cCLey01a80zv2IZQ== X-Gm-Message-State: AOJu0YzYXA+9gmDGZMg5NjrOA6MOL9jpjAYhJyF+4DDPCdvLUhbXJhw8 FmK528Jge0lTNoPP0yY3OS6kL7zE1fCYDVKmzj7QswQkMBRSuPagLRpkW1FQSEV4aZInYqhEqEm ht8bHJe/H9NxcE4esgbiH10yZyxCJ9aDyquQWS0+hBmFHrpq7n01EnS1OXp1MW14= X-Received: by 2002:a05:620a:318c:b0:795:4997:38e2 with SMTP id af79cd13be357-798101b4028mr479026485a.33.1718289747858; Thu, 13 Jun 2024 07:42:27 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHTM+W6GZjvLGLz8aosqs0Wzc//uyhZlOw1/ODilOa1Yg2TsPlvN5Rx32Ov40vf9Ca3HWUqjA== X-Received: by 2002:a05:620a:318c:b0:795:4997:38e2 with SMTP id af79cd13be357-798101b4028mr479023185a.33.1718289747450; Thu, 13 Jun 2024 07:42:27 -0700 (PDT) Received: from t14s.localdomain (c-76-28-97-5.hsd1.ma.comcast.net. [76.28.97.5]) by smtp.gmail.com with ESMTPSA id d75a77b69052e-441ef3d8826sm6750531cf.4.2024.06.13.07.42.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 07:42:27 -0700 (PDT) Message-ID: <1701c657627b1b2cc0867b4b8eb9ab1b20a66f35.camel@redhat.com> Subject: Re: [PATCH v3] gcc, libcpp: Add warning switch for "#pragma once in main file" [PR89808] From: David Malcolm To: Ken Matsui , gcc-patches@gcc.gnu.org Cc: jason@redhat.com Date: Thu, 13 Jun 2024 10:42:25 -0400 In-Reply-To: <20240613143140.660743-1-kmatsui@gcc.gnu.org> References: <20240302130436.2694515-1-kmatsui@gcc.gnu.org> <20240613143140.660743-1-kmatsui@gcc.gnu.org> User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00,BODY_8BITS,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 2024-06-13 at 07:31 -0700, Ken Matsui wrote: > This patch adds a warning switch for "#pragma once in main file".=C2=A0 > The > warning option name is Wpragma-once-outside-header, which is the same > as Clang. >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0PR preprocessor/89808 >=20 > gcc/c-family/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* c.opt (Wpragma_once_out= side_header): Define new option. >=20 > gcc/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* doc/invoke.texi (Warnin= g Options): Document > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0-Wno-pragma-once-outside-= header. >=20 > libcpp/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* include/cpplib.h (struc= t cpp_options): Define > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0cpp_warn_pragma_once_outs= ide_header. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0(cpp_warning_reason): Def= ine > CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* directives.cc (do_pragm= a_once): Use > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0cpp_warn_pragma_once_outs= ide_header and > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0CPP_W_PRAGMA_ONCE_OUTSIDE= _HEADER. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* init.cc (cpp_create_rea= der): Handle > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0cpp_warn_pragma_once_outs= ide_header. >=20 > gcc/testsuite/ChangeLog: >=20 > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* g++.dg/warn/Wno-pragma-= once-outside-header.C: New test. > =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0* g++.dg/warn/Wpragma-onc= e-outside-header.C: New test. >=20 > Signed-off-by: Ken Matsui [...snip...] Thanks for the updated patch. > @@ -7983,6 +7983,12 @@ Do not warn about misuses of pragmas, such as > incorrect parameters, > =C2=A0invalid syntax, or conflicts between pragmas.=C2=A0 See also > =C2=A0@option{-Wunknown-pragmas}. > =C2=A0 > +@opindex Wno-pragma-once-outside-header > +@opindex Wpragma-once-outside-header > +@item -Wno-pragma-once-outside-header > +Do not warn when @code{#pragma once} is used in a file that is not a > header > +file, such as a main file. > + > =C2=A0@opindex Wno-prio-ctor-dtor > =C2=A0@opindex Wprio-ctor-dtor > =C2=A0@item -Wno-prio-ctor-dtor Please run "make html && make regenerate-opt-urls" so that the diagnostic gets a documentation URL. Sorry that you have to do this manually (it's to avoid complicating the build dependencies for someone just building gcc). [...snip...] > diff --git a/libcpp/directives.cc b/libcpp/directives.cc > index 479f8c716e8..68f47104dea 100644 > --- a/libcpp/directives.cc > +++ b/libcpp/directives.cc > @@ -1588,8 +1588,12 @@ do_pragma (cpp_reader *pfile) > =C2=A0static void > =C2=A0do_pragma_once (cpp_reader *pfile) > =C2=A0{ > -=C2=A0 if (_cpp_in_main_source_file (pfile)) > -=C2=A0=C2=A0=C2=A0 cpp_error (pfile, CPP_DL_WARNING, "#pragma once in ma= in file"); > +=C2=A0 const unsigned char warn_level =3D > +=C2=A0=C2=A0=C2=A0 CPP_OPTION (pfile, cpp_warn_pragma_once_outside_heade= r); > + > +=C2=A0 if (warn_level && _cpp_in_main_source_file (pfile)) > +=C2=A0=C2=A0=C2=A0 cpp_warning (pfile, CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER, > +=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0 "#pragma once in main file"); Please put the "#pragma once" in the message in quotes, such as via: cpp_warning (pfile, CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER, "% in main file"); or via: cpp_warning (pfile, CPP_W_PRAGMA_ONCE_OUTSIDE_HEADER, "%qs in main file", "pragma once"); Although it's a minor style nit, I'm working on patches to automatically add URLs to GCC's documentation for certain quoted strings on sufficiently capable terminals (I've done command-line options, I'm working on attributes, and I hope to eventually do pragmas). Dave