public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66606] New: missing diagnostic on using function main
@ 2015-06-19 20:20 msebor at gcc dot gnu.org
  2021-08-05  7:31 ` [Bug c++/66606] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: msebor at gcc dot gnu.org @ 2015-06-19 20:20 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66606

            Bug ID: 66606
           Summary: missing diagnostic on using function main
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

While implementing a fix for pr66516 I noticed that GCC diagnoses some but not
all uses of main in a program (pursuant to 3.6.1, p3 of C++14.)  The following
test case shows the constructs that GCC does diagnose along with those it does
not.  The output below then shows the diagnostics produced by Clang for
comparison.  It's interesting that Clang includes the diagnostics in -Wmain. 
It might worth considering to do the same in GCC.

$ cat /build/tmp/u.cpp && ~/bin/gcc-5.1.0/bin/g++ -Wpedantic -c -o/dev/null
/build/tmp/u.cpp -std=c++11
#include <typeinfo>

int main () { }

typedef decltype (main) F;

F& foo () { return main; }

int bar () { return main (); }

const std::type_info &ti = typeid (main);

const bool e = noexcept (main);

const int i = (main, 0);

template <F> struct A { };
A<main> a;

template <F&> struct B { };
B<main> b;

/build/tmp/u.cpp: In function ‘int (& foo())()’:
/build/tmp/u.cpp:7:20: warning: ISO C++ forbids taking address of function
‘::main’ [-Wpedantic]
 F& foo () { return main; }
                    ^
/build/tmp/u.cpp: In function ‘int bar()’:
/build/tmp/u.cpp:9:27: warning: ISO C++ forbids taking address of function
‘::main’ [-Wpedantic]
 int bar () { return main (); }
                           ^
/build/tmp/u.cpp: At global scope:
/build/tmp/u.cpp:18:7: warning: ISO C++ forbids taking address of function
‘::main’ [-Wpedantic]
 A<main> a;
       ^


Clang output:

$ /build/llvm-3.6.0/bin/clang -Wall -Wpedantic -c -o/dev/null -std=c++11
/build/tmp/u.cpp
/build/tmp/u.cpp:5:19: warning: ISO C++ does not allow 'main' to be used by a
      program [-Wmain]
typedef decltype (main) F;
                  ^
/build/tmp/u.cpp:7:20: warning: ISO C++ does not allow 'main' to be used by a
      program [-Wmain]
F& foo () { return main; }
                   ^
/build/tmp/u.cpp:9:21: warning: ISO C++ does not allow 'main' to be used by a
      program [-Wmain]
int bar () { return main (); }
                    ^
/build/tmp/u.cpp:11:36: warning: ISO C++ does not allow 'main' to be used by a
      program [-Wmain]
const std::type_info &ti = typeid (main);
                                   ^
/build/tmp/u.cpp:13:26: warning: ISO C++ does not allow 'main' to be used by a
      program [-Wmain]
const bool e = noexcept (main);
                         ^
/build/tmp/u.cpp:15:16: warning: ISO C++ does not allow 'main' to be used by a
      program [-Wmain]
const int i = (main, 0);
               ^
/build/tmp/u.cpp:15:16: warning: expression result unused [-Wunused-value]
const int i = (main, 0);
               ^~~~
/build/tmp/u.cpp:18:3: warning: ISO C++ does not allow 'main' to be used by a
      program [-Wmain]
A<main> a;
  ^
/build/tmp/u.cpp:21:3: warning: ISO C++ does not allow 'main' to be used by a
      program [-Wmain]
B<main> b;
  ^
/build/tmp/u.cpp:13:12: warning: unused variable 'e' [-Wunused-const-variable]
const bool e = noexcept (main);
           ^
/build/tmp/u.cpp:15:11: warning: unused variable 'i' [-Wunused-const-variable]
const int i = (main, 0);
          ^
11 warnings generated.
>From gcc-bugs-return-489466-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Jun 19 20:28:11 2015
Return-Path: <gcc-bugs-return-489466-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 67992 invoked by alias); 19 Jun 2015 20:28:11 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 67954 invoked by uid 48); 19 Jun 2015 20:28:07 -0000
From: "msebor at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66606] missing diagnostic on using function main
Date: Fri, 19 Jun 2015 20:28:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 5.1.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: msebor at gcc dot gnu.org
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:
Message-ID: <bug-66606-4-yJC7h00fLS@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66606-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66606-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg01798.txt.bz2
Content-length: 596

https://gcc.gnu.org/bugzilla/show_bug.cgi?idf606

--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
One other observation (and actually the reason why I found this problem) is
that the diagnostic GCC issues for the call to main in bar:

int bar () { return main (); }

is misleading.  The operand of the return statement is a call to main, not an
ADDR_EXPR.  (It just happens to be easy to handle both in cp_build_addr_expr_1
because it doesn't distinguish between the two.)  The Clang diagnostic doesn't
suffer from the same problem (and so can be used in all other contexts.)


^ permalink raw reply	[flat|nested] 2+ messages in thread

* [Bug c++/66606] missing diagnostic on using function main
  2015-06-19 20:20 [Bug c++/66606] New: missing diagnostic on using function main msebor at gcc dot gnu.org
@ 2021-08-05  7:31 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-05  7:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66606

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|2015-08-19 00:00:00         |2021-8-5

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
These are the ones which we don't catch right now:

#include <typeinfo>

int main () { }

typedef decltype (main) F; // xfail

F& foo () { return main; } // { dg-error "" }

int bar () { return main (); } // xfail

const std::type_info &ti = typeid (main); // xfail

const bool e = noexcept (main); // xfail

const int i = (main, 0); // xfail

template <F> struct A { };
A<main> a; // { dg-error "" }

template <F&> struct B { };
B<main> b; // { dg-error "" }

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-05  7:31 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-19 20:20 [Bug c++/66606] New: missing diagnostic on using function main msebor at gcc dot gnu.org
2021-08-05  7:31 ` [Bug c++/66606] " pinskia at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).