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

            Bug ID: 99380
           Summary: [modules] Unexpected MODULE-EXPORT request when
                    partially preprocessing header unit
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: boris at kolpackov dot net
  Target Milestone: ---

A change between 11.0.0 20210217 and 11.0.1 20210304 causes an unexpected
MODULE-EXPORT request when partially preprocessing a header unit that imports
another header unit:

cat <<EOF >hello.hxx
#pragma once

#if 1
import <string_view>;
#else
#include <string_view>
#endif

namespace hello
{
  void
  say_hello (const std::string_view& name);
}
EOF

cat <<EOF >mapper
#!/usr/bin/env bash

function info () { echo "$*" 1>&2; }
function resp () { info "  < $*"; echo "$*"; }

while read l; do
  info "  > $l"

  case "$l" in
    HELLO*)
      resp "HELLO 1 test ;"
      ;;
    MODULE-REPO)
      resp "PATHNAME /"
      ;;
    MODULE-EXPORT*"string_view 1"|MODULE-IMPORT*string_view)
      resp "PATHNAME $(pwd)/string_view.gcm"
      ;;
    INCLUDE-TRANSLATE*)
      resp "BOOL FALSE"
      ;;
    MODULE-COMPILED*)
      resp "OK"
      ;;
    *)
      resp "ERROR 'unexpected request: $l'"
      ;;
  esac
done
EOF

chmod ugo+x mapper

g++ -std=c++2a -fmodules-ts -fmodule-mapper='|./mapper' -fmodule-header -x
c++-header .../include/c++/11.0.1/string_view
g++ -std=c++2a -fmodules-ts -fmodule-mapper='|./mapper' -E -fdirectives-only -o
hello.ii -fmodule-header -x c++-header hello.hxx

  > HELLO 1 GCC '' ;
  < HELLO 1 test ;
  > MODULE-REPO
  < PATHNAME /
  > MODULE-EXPORT ./hello.hxx ;
  < ERROR 'unexpected request: MODULE-EXPORT ./hello.hxx ;'
  > MODULE-IMPORT
/home/boris/work/build2/tests/modules/gcc2/gcc-install/include/c++/11.0.1/string_view
hello.hxx: error: unknown Compiled Module Interface: unexpected request:
MODULE-EXPORT ./hello.hxx ;

However, if I change hello.hxx to #include instead of import string_view, then
there is no MODULE-EXPORT:

g++ -std=c++2a -fmodules-ts -fmodule-mapper='|./mapper' -E -fdirectives-only -o
hello.ii -fmodule-header -x c++-header hello.hxx

  > HELLO 1 GCC '' ;
  < HELLO 1 test ;
  > MODULE-REPO
  < PATHNAME /
  > INCLUDE-TRANSLATE
/home/boris/work/build2/tests/modules/gcc2/gcc-install/include/c++/11.0.1/string_view
  < BOOL FALSE
  ...

Reply via email to