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

            Bug ID: 97570
           Summary: avr-gcc: error: 'void* memalign' redeclared as
                    different kind of entity
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: matwey.kornilov at gmail dot com
  Target Milestone: ---

Hi,

While I am trying to build avr-gcc from master with Freestanding C++ standard
library on x86_64 host system, I see the following compile error:


../../../../libstdc++-v3/libsupc++/new_opa.cc:56:18: error: 'void* memalign'
redeclared as different kind of entity
   56 |   void *memalign(size_t alignment, size_t size);
      |                  ^~~~~~
../../../../libstdc++-v3/libsupc++/new_opa.cc:39:18: note: previous declaration
'void* memalign(std::size_t, std::size_t)'
   39 | extern "C" void *memalign(std::size_t boundary, std::size_t size);
      |                  ^~~~~~~~
../../../../libstdc++-v3/libsupc++/new_opa.cc:56:18: error: 'size_t' was not
declared in this scope; did you mean 'std::size_t'?
   56 |   void *memalign(size_t alignment, size_t size);
      |                  ^~~~~~
      |                  std::size_t
In file included from ../../../../libstdc++-v3/libsupc++/new_opa.cc:26:
/usr/src/gcc/avr-obj/avr/libstdc++-v3/include/avr/bits/c++config.h:280:33:
note: 'std::size_t' declared here
  280 |   typedef __SIZE_TYPE__         size_t;
      |                                 ^~~~~~
../../../../libstdc++-v3/libsupc++/new_opa.cc:56:36: error: 'size_t' was not
declared in this scope; did you mean 'std::size_t'?
   56 |   void *memalign(size_t alignment, size_t size);
      |                                    ^~~~~~
      |                                    std::size_t
In file included from ../../../../libstdc++-v3/libsupc++/new_opa.cc:26:
/usr/src/gcc/avr-obj/avr/libstdc++-v3/include/avr/bits/c++config.h:280:33:
note: 'std::size_t' declared here
  280 |   typedef __SIZE_TYPE__         size_t;
      |                                 ^~~~~~


I use binutils 2.35 and gcc 47d13acbda9a5d8eb57ff169ba74857cd54108e4


Steps to reproduce:

1. Build and install gcc without libstdc++:

# ../configure --prefix=/usr --target=avr --enable-languages=c,c++
--disable-nls --disable-libssp --with-dwarf2
# make
# make install

2. Build and install avr-libc 2.0

# ../configure --prefix=/usr --build=`../config.guess` --host=avr
# make
# make install

3. Rebuild gcc with Freestanding libstdc++

# ../configure --prefix=/usr --target=avr --enable-languages=c,c++
--disable-nls --disable-libssp --with-dwarf2 --with-newlib
--disable-__cxa_atexit --disable-threads --disable-shared --enable-static
--disable-sjlj-exceptions --enable-libstdcxx --enable-lto
--disable-hosted-libstdcxx
# make

See the error.


The following simple patch fixes the issue:

--- a/libstdc++-v3/libsupc++/new_opa.cc
+++ b/libstdc++-v3/libsupc++/new_opa.cc
@@ -53,7 +53,7 @@ extern "C"
 # elif _GLIBCXX_HAVE_POSIX_MEMALIGN
   void *posix_memalign(void **, size_t alignment, size_t size);
 # elif _GLIBCXX_HAVE_MEMALIGN
-  void *memalign(size_t alignment, size_t size);
+  void *memalign(std::size_t alignment, std::size_t size);
 # endif
 }
 #endif

Then gcc and libstdc++ are compiled and installed successfully without any
further errors. But I doubt that this is correct way to handle this issue.

Reply via email to