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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Nathan Sidwell <nat...@gcc.gnu.org>:

https://gcc.gnu.org/g:14886cbe300c144a4390245d0515cdf28fc5f68f

commit r11-7307-g14886cbe300c144a4390245d0515cdf28fc5f68f
Author: Nathan Sidwell <nat...@acm.org>
Date:   Fri Feb 19 13:10:27 2021 -0800

    c++: Incorrect module-number ordering [PR 98741]

    One of the very strong invariants in modules is that module numbers
    are allocated such that (other than the current TU), all imports have
    lesser module numbers, and also that the binding vector is only
    appended to with increasing module numbers.   This broke down when
    module-directives became a thing and the preprocessing became entirely
    decoupled from parsing.  We'd load header units and their macros (but
    not symbols of course) during preprocessing.  Then we'd load named
    modules during parsing.  This could lead to the situation where a
    header unit appearing after a named import had a lower module number
    than the import.  Consequently, if they both bound the same
    identifier, the binding vector would be misorderd and bad things
    happen.

    This patch restores a pending import queue I previously had, but in
    simpler form (hurrah).  During preprocessing we queue all
    module-directives and when we meet one for a header unit we do the
    minimal loading for all of the queue, so they get appropriate
    numbering.  Then we load the preprocessor state for the header unit.

            PR c++/98741
            gcc/cp/
            * module.cc (pending_imports): New.
            (declare_module): Adjust test condition.
            (name_pending_imports): New.
            (preprocess_module): Reimplement using pending_imports.
            (preprocessed_module): Move name-getting to name_pending_imports.
            * name-lookup.c (append_imported_binding_slot): Assert module
            ordering is increasing.
            gcc/testsuite/
            * g++.dg/modules/pr98741_a.H: New.
            * g++.dg/modules/pr98741_b.H: New.
            * g++.dg/modules/pr98741_c.C: New.
            * g++.dg/modules/pr98741_d.C: New.

Reply via email to