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

            Bug ID: 81609
           Summary: incompatible extern C declarations of the same extern
                    function at local scope accepted
           Product: gcc
           Version: 8.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: ---

Somewhat similar to bug 81608, G++ correctly rejects a function redeclaration
at local scope that's incompatible with a prior declaration of the same
function at namespace scope but only so long as the function has C++ language
linkage.

G++ fails to reject the same incompatible redeclaration of functions with C
language linkage.

Clang rejects both as expected.

$ cat t.C && gcc -S -Wall -Wextra -Wpedantic t.C
extern "C" {

int foo (void) { return 123; }

char* f (void)
{
  extern char* foo (void);

  return foo ();
}

}

int bar (void) { return 123; }

char* g (void)
{
  extern char* bar (void);

  return bar ();
}

t.C: In function ‘char* g()’:
t.C:18:16: error: local external declaration ‘char* bar()’ [-fpermissive]
   extern char* bar (void);
                ^~~
t.C:14:5: note: does not match previous declaration ‘int bar()’
 int bar (void) { return 123; }
     ^~~

Reply via email to