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

            Bug ID: 105491
           Summary: Usafe of __constinit with -std=c++ does is rejected
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: mpolacek at gcc dot gnu.org
  Target Milestone: ---

Created attachment 52930
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52930&action=edit
test-case

Noticed that in protobuf package:
https://github.com/protocolbuffers/protobuf/issues/9916

$ g++ 12.ii -c -std=c++11
x.cc:39:123: error: ‘constinit’ variable
‘_ProtobufCFileOptions_default_instance_’ does not have a constant initializer
   39 | PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ProtobufCFileOptionsDefaultTypeInternal
_ProtobufCFileOptions_default_instance_;
      |                                                                        
                                                 
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x.cc:39:123: error:
‘ProtobufCFileOptionsDefaultTypeInternal{ProtobufCFileOptionsDefaultTypeInternal::<unnamed
union>{ProtobufCFileOptions{google::protobuf::Message{google::protobuf::MessageLite{((&
ProtobufCFileOptions::_ZTV20ProtobufCFileOptions) + 16),
google::protobuf::internal::InternalMetadata{0}}},
google::protobuf::internal::HasBits<1>{uint32_t [1]()},
google::protobuf::internal::CachedSize{std::atomic<int>{std::__atomic_base<int>{0}}},
google::protobuf::internal::ArenaStringPtr{google::protobuf::internal::TaggedStringPtr{((void*)(&
google::protobuf::internal::fixed_address_empty_string))}}, false, false,
false, true, true}}}’ is not a constant expression
x.cc:53:126: error: ‘constinit’ variable
‘_ProtobufCMessageOptions_default_instance_’ does not have a constant
initializer
   53 | PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ProtobufCMessageOptionsDefaultTypeInternal
_ProtobufCMessageOptions_default_instance_;
      |                                                                        
                                                    
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x.cc:53:126: error:
‘ProtobufCMessageOptionsDefaultTypeInternal{ProtobufCMessageOptionsDefaultTypeInternal::<unnamed
union>{ProtobufCMessageOptions{google::protobuf::Message{google::protobuf::MessageLite{((&
ProtobufCMessageOptions::_ZTV23ProtobufCMessageOptions) + 16),
google::protobuf::internal::InternalMetadata{0}}},
google::protobuf::internal::HasBits<1>{uint32_t [1]()},
google::protobuf::internal::CachedSize{std::atomic<int>{std::__atomic_base<int>{0}}},
google::protobuf::internal::ArenaStringPtr{google::protobuf::internal::TaggedStringPtr{0}},
false, true}}}’ is not a constant expression
x.cc:65:124: error: ‘constinit’ variable
‘_ProtobufCFieldOptions_default_instance_’ does not have a constant initializer
   65 | PROTOBUF_ATTRIBUTE_NO_DESTROY PROTOBUF_CONSTINIT
PROTOBUF_ATTRIBUTE_INIT_PRIORITY1 ProtobufCFieldOptionsDefaultTypeInternal
_ProtobufCFieldOptions_default_instance_;
      |                                                                        
                                                  
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
x.cc:65:124: error:
‘ProtobufCFieldOptionsDefaultTypeInternal{ProtobufCFieldOptionsDefaultTypeInternal::<unnamed
union>{ProtobufCFieldOptions{google::protobuf::Message{google::protobuf::MessageLite{((&
ProtobufCFieldOptions::_ZTV21ProtobufCFieldOptions) + 16),
google::protobuf::internal::InternalMetadata{0}}},
google::protobuf::internal::HasBits<1>{uint32_t [1]()},
google::protobuf::internal::CachedSize{std::atomic<int>{std::__atomic_base<int>{0}}},
false}}}’ is not a constant expression
x.cc: In member function ‘virtual uint8_t*
ProtobufCMessageOptions::_InternalSerialize(uint8_t*,
google::protobuf::io::EpsCopyOutputStream*) const’:
x.cc:499:1: warning: no return statement in function returning non-void
[-Wreturn-type]
  499 | }
      | ^

$ g++ 12.ii -c -std=c++17
x.cc: In member function ‘virtual uint8_t*
ProtobufCMessageOptions::_InternalSerialize(uint8_t*,
google::protobuf::io::EpsCopyOutputStream*) const’:
x.cc:499:1: warning: no return statement in function returning non-void
[-Wreturn-type]
  499 | }
      | ^

Reply via email to