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 A436E3858D39 for ; Fri, 2 Dec 2022 15:46:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A436E3858D39 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669995999; 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=0MADdxMqI2mixd8+03Pn7XHZObYezJpzdPkmxXGArik=; b=ZbJdS5gWSH5Tb10TE0VwbF68nIVzAg38+7Zx7K0M5Z4M7khOA7ph/7Cq4d0NSpsHolHegF Qm/zQvN/vFDEx4CY/sbo57iXalwgMtoAZ9aBQFKGQZjgKvcDGgJkyVr4Ahg5tNDyEp8CSj Gec+hIE2gR1s/DAvCiB/8R3WTKQqslk= Received: from mail-qt1-f197.google.com (mail-qt1-f197.google.com [209.85.160.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-336-FbeukVBaNO-97GJK9LZ_aA-1; Fri, 02 Dec 2022 10:46:38 -0500 X-MC-Unique: FbeukVBaNO-97GJK9LZ_aA-1 Received: by mail-qt1-f197.google.com with SMTP id u31-20020a05622a199f00b003a51fa90654so18630610qtc.19 for ; Fri, 02 Dec 2022 07:46:38 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=user-agent:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=0MADdxMqI2mixd8+03Pn7XHZObYezJpzdPkmxXGArik=; b=SqwMEe5RspemRdgLFcUeoJKyIuVTbnKk31NIAIv1nth2xGaBernLQiAJf30Cv3pv2X 56hsfPaYv4+/nUpo6qtDhqtWliRRltPBOPQJBVS9gBgvXYY8elplp3n4BKdfxF5jA1SO +SYscQsuKJxGh/6lZQ2XCpLRu8xVcvZbBiLj+pNWcgQVBTidYqb+IP+bpxLBFW+dNE5e CturnueXiqC6BTRBAi23ZMNvjFD6HELrXOWuvXXbOHC4K+yf55pFp6dvrqM6JRhUhuHS jIvIa9ZDAMvsac9ErrxHQRJ7E37gQ0gVG4qOw93olVRt73MMEOQeTKzbri9Dd0c9nPJV Vx/Q== X-Gm-Message-State: ANoB5pnVIcCinQW6kCF1qCHy0aqclZRqguiOPwJluMGkGuEeDXXW6Rg0 52RrGR1i/Yq34CrsdOf6QvcCiL7hC9aSADlZRCQ0dUS2Axvgo/K3VHhCEdjukVbrCioG0DUoVhr OCcgpwQ8= X-Received: by 2002:a05:622a:181b:b0:3a6:9a9b:ae9a with SMTP id t27-20020a05622a181b00b003a69a9bae9amr2171677qtc.142.1669995997513; Fri, 02 Dec 2022 07:46:37 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JK1AR9tm861RjejsgXxknItOqx88Q7tMwfsBZH6rG0kVjj+wKAE2KCXufGGPf+iVKg20i7Q== X-Received: by 2002:a05:622a:181b:b0:3a6:9a9b:ae9a with SMTP id t27-20020a05622a181b00b003a69a9bae9amr2171665qtc.142.1669995997269; Fri, 02 Dec 2022 07:46:37 -0800 (PST) Received: from redhat.com (2603-7000-9500-2e39-0000-0000-0000-1db4.res6.spectrum.com. [2603:7000:9500:2e39::1db4]) by smtp.gmail.com with ESMTPSA id c19-20020ac81113000000b003a57eb7f212sm4335426qtj.10.2022.12.02.07.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Dec 2022 07:46:36 -0800 (PST) Date: Fri, 2 Dec 2022 10:46:34 -0500 From: Marek Polacek To: =?utf-8?B?SmnFmcOt?= Wolker Cc: gcc@gcc.gnu.org Subject: Re: Feature request: Warning when .c file gets #include'd Message-ID: References: <87359xyhsn.fsf@gmail.com> MIME-Version: 1.0 In-Reply-To: <87359xyhsn.fsf@gmail.com> User-Agent: Mutt/2.2.7 (2022-08-07) X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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 Fri, Dec 02, 2022 at 03:57:44PM +0100, Jiří Wolker via Gcc wrote: > > Hi, > > I've met a guy that is learning C and got stuck when the linker produced > a screenful of messages about that he did something define multiple > times. The cause of the problem was trivial: > > He did ``#include "something.c"'' in his code. > > In the past, I also did this thing multiple times and I would appreciate > a warning produced by the gcc when compiling C/C++ file that includes a > file ending in .c, .cx, .cpp or .cxx. > > What do you think about that? > > I would prefer to make this enabled when -Wextra is used. The problem is that a lot of beginners don't use -Wextra, so the warning wouldn't be displayed anyway. > Based on my past experience with using .c files in the include > directive, I can think of these problems. > > - Sometimes, I want to include a file that is definitely not a header, > but also it is not a stand-alone source file. I personally prefer > using .inc suffix, but some people possibly terminate the file names > with .c suffix like a source file. > > Example: list of enum fields included from a separate file that was > generated by a script > > - In some projects, someone can deliberately want to include another > source file. For example, this can happen when doing unit tests and > you do not want to specify the source file name on the command line. Indeed, e.g. elfutils uses this a lot: #define LIBELFBITS 64 #include "elf32_xlatetom.c" We use including .c in our testsuite a lot as well. So I'm afraid this would get -1 from me personally, sorry. > If you accept that, I can try to implement that. (That would be my first > contribution to this project and I do not know gcc codebase, but it > looks like a relatively simple change.) Do you think that it would need > a copyright assignment? I think it would. Thanks, Marek