[Bug c++/17811] New: [4.0.0 Regression] Implicit extern "C" is broken resulting in C++ mangling function names in assert.h and ctype.h

danglin at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Sun Oct 3 16:25:00 GMT 2004


These ports don't define NO_IMPLICIT_EXTERN_C.  The headers for assert.h
and ctype.h don't provide __cplusplus conditionalized extern "C".  From the
comments in assert.h, this is intentional.

The handling of implicit extern "C" in 4.0.0 doesn't work because the
processing of tokens is now deferred until after all the headers have
been read by the C frontend.  We have the following code in c-lex.c:

#ifndef NO_IMPLICIT_EXTERN_C
          if (c_header_level)
            ++c_header_level;
          else if (new_map->sysp == 2)
            {
              c_header_level = 1;
              ++pending_lang_change;
            }
#endif
        }
    }
  else if (new_map->reason == LC_LEAVE)
    {
#ifndef NO_IMPLICIT_EXTERN_C
      if (c_header_level && --c_header_level == 0)
        {
          if (new_map->sysp == 2)
            warning ("badly nested C headers from preprocessor");
          --pending_lang_change;
        }
#endif

pending_lang_change is incremented when a C system header is entered
and decremented when the header is left.  The corresponding code in
cp/parser.c is:

      /* The C lexer modifies PENDING_LANG_CHANGE when it wants the
         parser to enter or exit implicit `extern "C"' blocks.  */
      while (pending_lang_change > 0)
        {
          push_lang_context (lang_name_c);
          --pending_lang_change;
        }
      while (pending_lang_change < 0)
        {
          pop_lang_context ();
          ++pending_lang_change;
        }

      /* Parse the declaration itself.  */
      cp_parser_declaration (parser);

This only works if the declarations are parsed immediately after c-lex.c
has incremented/decremented pending_lang_change.  However, the parser now
defers parsing of declarations until after all the header files have been
processed and the tokens stashed in a varray.

-- 
           Summary: [4.0.0 Regression] Implicit extern "C" is broken
                    resulting in C++ mangling function names in assert.h and
                    ctype.h
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: danglin at gcc dot gnu dot org
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: powerpc-ibm-aix4.x, powerpc-ibm-aix5.x
  GCC host triplet: powerpc-ibm-aix4.x, powerpc-ibm-aix5.x
GCC target triplet: powerpc-ibm-aix4.x, powerpc-ibm-aix5.x


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=17811



More information about the Gcc-bugs mailing list