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

            Bug ID: 93169
           Summary: [10 regression] Variable incorrectly put into readonly
                    section.
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hubicka at gcc dot gnu.org
  Target Milestone: ---

This is testcase by Mark Williams who also bisected it
template <typename a> class b {
  struct c {
    a h;
    constexpr c() {}
    ~c() {}
  } d;
};
struct e {
  int g;
  e() { g = 2; }
};
main() { static const b<e> f; }

$ /aux/hubicka/trunk-install/bin/g++ -O2 t.C
t.C:12:1: warning: ISO C++ forbids declaration of ‘main’ with no type
[-Wreturn-type]
   12 | main() { static const b<e> f; }
      | ^~~~
$ ./a.out
Segmentation fault
$ /aux/hubicka/9-install/bin/g++ -O2 t.C
At.C:12:6: warning: ISO C++ forbids declaration of ‘main’ with no type
[-Wreturn-type]
   12 | main() { static const b<e> f; }
      |      ^
$ ./a.out

It is caused by 
commit 88bbd5a94e06eb42a5ed84a3ff6da498bea229e9 (HEAD, refs/bisect/bad)
Author:     mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
AuthorDate: Mon Aug 19 13:59:13 2019 +0000
Commit:     mpolacek <mpolacek@138bc75d-0d04-0410-961f-82ee72b054a4>
CommitDate: Mon Aug 19 13:59:13 2019 +0000

            PR c++/91264 - detect modifying const objects in constexpr.
            * constexpr.c (modifying_const_object_error): New function.
            (cxx_eval_call_expression): Set TREE_READONLY on a CONSTRUCTOR of
            a const-qualified object after it's been fully constructed.
            (modifying_const_object_p): New function.
            (cxx_eval_store_expression): Detect modifying a const object
            during constant expression evaluation.
            (cxx_eval_increment_expression): Use a better location when
building
            up the store.
            (cxx_eval_constant_expression) <case DECL_EXPR>: Mark a constant
            object's constructor TREE_READONLY.

and goes away after reverting the cxx_eval_call_expression hunk.

Reply via email to