Bug 43105 - Document restrictions on mixing -fno-rtti and -frtti
Summary: Document restrictions on mixing -fno-rtti and -frtti
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: documentation
Depends on:
Blocks:
 
Reported: 2010-02-17 15:32 UTC by Jeffrey Yasskin
Modified: 2018-11-11 22:49 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2017-08-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Yasskin 2010-02-17 15:32:14 UTC
http://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/C_002b_002b-Dialect-Options.html#index-fno_002drtti-148 doesn't mention any restrictions on compiling programs with some translation units compiled with -frtti, and others compiled with -fno-rtti. Yet there are such restrictions. For example, programs don't link when a -frtti class is derived from a -fno-rtti base class. Any restrictions like that should be documented or fixed.
Comment 1 Eric Gallager 2017-08-17 21:57:41 UTC
Redoing https://gcc.gnu.org/ml/gcc-bugs/2017-08/msg01628.html

Eric Gallager <egallager at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2017-08-14
                 CC|                            |egallager at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Eric Gallager <egallager at gcc dot gnu.org> ---
Confirmed, text in the current docs is still pretty much the same as it was in
4.4.3.
Comment 2 Eric Gallager 2018-08-25 03:03:46 UTC
cc-ing docs co-maintainers
Comment 3 Jonathan Wakely 2018-08-31 13:50:00 UTC
(In reply to Jeffrey Yasskin from comment #0)
> programs don't link when a -frtti class is derived from a -fno-rtti base
> class.

It's more complicated than that. The ABI defines when RTTI is emitted:
https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-rtti

There's only a problem when compiling a key function with -fno-rtti, and other translation units compiled with -frtti have no way to know how the key function was compiled.

For example, given:

struct A {
  A();
  ~A();
};

struct B {
  B();
  virtual ~B() { }
};

struct C {
  C();
  virtual ~C();
};

A and B can always be derived from unconditionally. If C::~C() is compiled with -fno-rtti then classes that derive from C must also use -fno-rtti to compile their key function (and if they don't have a key function, then all uses of C that need a definition must be compiled with -fno-rtti).

I don't think this can be fixed. Documenting it is non-trivial.

I went to see what Clang does, and I can't even find -frtti / -fno-rtti in the manual, so we're doing better than that!
Comment 4 sandra 2018-11-08 20:34:58 UTC
It sounds to me like the right solution here is just to add a vague warning that mixing -frtti and -fno-rtti code may not always work, citing the base class example in the issue problem statement.  WDYT?
Comment 5 Jonathan Wakely 2018-11-09 01:12:07 UTC
Works for me.
Comment 6 sandra 2018-11-11 22:46:38 UTC
Author: sandra
Date: Sun Nov 11 22:46:00 2018
New Revision: 266020

URL: https://gcc.gnu.org/viewcvs?rev=266020&root=gcc&view=rev
Log:
2018-11-11  Sandra Loosemore  <sandra@codesourcery.com>

	PR c++/43105

	gcc/
	* doc/invoke.texi (C++ Dialect Options): Add warning about mixing
	-frtti and -fno-rtti code.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/doc/invoke.texi
Comment 7 sandra 2018-11-11 22:49:07 UTC
Fixed on trunk.