This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/24928] New: Trivial static const objects should go to .rodata

If a class has a trivial constructor that can be completely inlined and
consists of simply initializing member variables, then static const instances
of this class can be initialized at compile time and placed into .rodata. This
would be the same behaviour that C has for static const structs and arrays.

struct A {
    inline A (int v) : m_v (v) {}
    int m_v;

int main (void)
    static const A s_v (42);
    return (0);

Compiles to (with -fno-threadsafe-statics):

.globl main
        .type   main, @function
        cmpb    $0, _ZGVZ4mainE3s_v
        jne     .L2
        movl    $42, _ZZ4mainE3s_v
        movb    $1, _ZGVZ4mainE3s_v
        xorl    %eax, %eax

With the object being initialized at runtime as if it mattered. Because the
values of the member variables can not be changed after initialization, there
is no reason to do this at runtime. Because the constructor doesn't do
anything, this would not conflict with C++'s create-on-call mandate.

Because of this behaviour there is no way to create compiled-in const objects
just like creating const structs or arrays in C.

           Summary: Trivial static const objects should go to .rodata
           Product: gcc
           Version: 4.0.2
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: msharov at hotmail dot com
 GCC build triplet: athlon-gnu-linux
  GCC host triplet: athlon-gnu-linux
GCC target triplet: athlon-gnu-linux

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]