This is the mail archive of the
gcc-prs@gcc.gnu.org
mailing list for the GCC project.
optimization/7708: g++ -O inserts definition of std::string::replace in library module
- From: Castalia at azstarnet dot com
- To: gcc-gnats at gcc dot gnu dot org
- Date: 24 Aug 2002 01:04:47 -0000
- Subject: optimization/7708: g++ -O inserts definition of std::string::replace in library module
- Reply-to: Castalia at azstarnet dot com
>Number: 7708
>Category: optimization
>Synopsis: g++ -O inserts definition of std::string::replace in library module
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: unassigned
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Aug 23 18:06:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Bradford Castalia
>Release: gcc version 3.1.1 20020617 (prerelease) [FreeBSD]
>Organization:
>Environment:
FreeBSD idaeim 4.6-STABLE FreeBSD 4.6-STABLE #0: Mon Aug 5 19:42:48 MST 2002
Configured with: ./..//gcc-20020617/configure --disable-nls --with-gnu-as --with-gnu-ld --with-gxx-include-dir=/usr/local/lib/gcc-lib/i386-portbld-freebsd4.6/3.1.1/include/g++ --disable-libgcj --disable-shared --prefix=/usr/local i386-portbld-freebsd4.6
Thread model: posix
>Description:
Use of -O with g++ when compiling a class that uses the
std::string methods replace and/or erase generates a
definition of the replace method in the object file. When
the object file is used as a library module this results
in multiple definition error at link time when the problem
has occured in more than one module.
>How-To-Repeat:
Separate the attached file into Test.h, Test.cpp, and
Makefile files. Use gmake with the Makefile to compile
the object module and place it in the library; or just
compile the object file with "g++ -O -c -o Test.o Test.cpp".
Examine the results with nm. Notice the definition of the
std::string::replace method in the object file. Recompile
without the -O option. Notice that the definition of the
std::string::replace method is no longer present in the
nm report of the object file.
>Fix:
A) Don't use optimization (sigh).
B) Note this "side effect" of optimization in the docs.
C) Prevent optimization from generating method definitions
not defined by the user code itself.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="Test"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="Test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