This is an archive of the discontinued LLVM Phabricator instance.

[flang][NFC] Add a no-arg constructor for `Verbatim`.
ClosedPublic

Authored by rupprecht on Dec 2 2022, 1:35 PM.

Details

Summary

In C++20, types that declare or delete any constructors are no longer aggregates, breaking compilation of many existing uses of aggregate initialization.

Although Verbatim declares itself to not have a no-arg default constructor, this is circumvented in basic-parsers.h which returns a RESULT{} a.k.a. Verbatim{}. Adding the no-arg constructor while still deleting the copy/assignment constructors maintains the current state and also supports eventually building this in c++20 mode.

Fix suggested in https://discourse.llvm.org/t/build-failure-when-attempting-to-build-flang-with-c-20/66953.

Diff Detail

Event Timeline

rupprecht created this revision.Dec 2 2022, 1:35 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptDec 2 2022, 1:35 PM
Herald added a subscriber: dmgreen. · View Herald Transcript
rupprecht requested review of this revision.Dec 2 2022, 1:35 PM

Where in basic-parsers.h is a Verbatim constructed with no argument? That would be somewhat dangerous since Verbatim::source really should be valid.

I doubt it; the template function "verbatim()" defined near the end of token-parsers.h is going to construct a Verbatim on whatever the result type of the argument is -- and in the case of a "..."_tok token, that's a Success indicator.

I doubt it; the template function "verbatim()" defined near the end of token-parsers.h is going to construct a Verbatim on whatever the result type of the argument is -- and in the case of a "..."_tok token, that's a Success indicator.

I agree that *that* verbatim instance is valid, but the type of it gets interred by a template method, and some machinery attempts to construct a no-arg version.

The source is this parser:

TYPE_PARSER(sourced(construct<OpenMPCancellationPointConstruct>(
    verbatim("CANCELLATION POINT"_tok), Parser<OmpCancelType>{})))

The fully expanded type of that: Fortran::parser::SourcedParser<Fortran::parser::ApplyConstructor<Fortran::parser::OpenMPCancellationPointConstruct, Fortran::parser::SourcedParser<Fortran::parser::ApplyConstructor<Fortran::parser::Verbatim, Fortran::parser::TokenStringMatch<false, false>>>, Fortran::parser::Parser<Fortran::parser::OmpCancelType>>>

The case of a`Success` verbatim token in ApplyConstructor returns a no-arg object here: https://github.com/llvm/llvm-project/blob/a74c5707be279bdddb51fe49aa9383c1ddc99fbe/flang/lib/Parser/basic-parsers.h#L751

std::optional<resultType> ParseOne(ParseState &state) const {
  if constexpr (std::is_same_v<Success, typename PARSER::resultType...>) {
    if (std::get<0>(parsers_).Parse(state)) {
      return RESULT{};
    }
klausler accepted this revision.Dec 2 2022, 2:32 PM
This revision is now accepted and ready to land.Dec 2 2022, 2:32 PM
This revision was automatically updated to reflect the committed changes.