Skip to content

Commit 066bb6b

Browse files
jensmaurertkoeppe
authored andcommitted
[cpp.import] Clarify header units as the source of macro definitions.
1 parent b0da187 commit 066bb6b

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

source/preprocessor.tex

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -811,18 +811,22 @@
811811
are processed just as in normal text
812812
(i.e., each identifier currently defined as a macro name
813813
is replaced by its replacement list of preprocessing tokens).
814+
\begin{note}
814815
An \tcode{import} directive
815816
matching the first two forms of a \grammarterm{pp-import}
816817
instructs the preprocessor to import macros
817818
from the header unit\iref{module.import}
818-
denoted by the \grammarterm{header-name}.
819+
denoted by the \grammarterm{header-name},
820+
as described below.
821+
\end{note}
819822
\indextext{point of!macro import|see{macro, point of import}}%
820823
The \defnx{point of macro import}{macro!point of import} for the
821824
first two forms of \grammarterm{pp-import} is
822825
immediately after the \grammarterm{new-line} terminating
823826
the \grammarterm{pp-import}.
824827
The last form of \grammarterm{pp-import} is only considered
825-
if the first two forms did not match.
828+
if the first two forms did not match, and
829+
does not have a point of macro import.
826830

827831
\pnum
828832
If a \grammarterm{pp-import} is produced by source file inclusion
@@ -862,30 +866,33 @@
862866
are encouraged to not treat them
863867
as being introduced by a \tcode{\#define} directive.
864868
\end{note}
865-
Importing macros from a header unit makes macro definitions
866-
from a translation unit visible in other translation units.
867869
Each macro definition has at most one point of definition in
868870
each translation unit and at most one point of undefinition, as follows:
869871
\begin{itemize}
870872
\item
871873
\indextext{point of!macro definition|see{macro, point of definition}}%
872874
The \defnx{point of definition}{macro!point of definition}
873-
of a macro definition within a translation unit
874-
is the point at which its \tcode{\#define} directive occurs (in the translation
875-
unit containing the \tcode{\#define} directive), or,
875+
of a macro definition within a translation unit $T$ is
876+
\begin{itemize}
877+
\item
878+
if the \tcode{\#define} directive of the macro definition occurs within $T$,
879+
the point at which that directive occurs, or otherwise,
880+
\item
876881
if the macro name is not lexically identical to a keyword\iref{lex.key}
877882
or to the \grammarterm{identifier}{s} \tcode{module} or \tcode{import},
878-
the first point
879-
of macro import of a translation unit containing a point of definition for the
880-
macro definition, if any (in any other translation unit).
883+
the first point of macro import in $T$ of a header unit
884+
containing a point of definition for the macro definition, if any.
885+
\end{itemize}
886+
In the latter case, the macro is said
887+
to be \defnx{imported}{macro!import} from the header unit.
881888

882889
\item
883890
\indextext{point of!macro undefinition|see{macro, point of undefinition}}%
884891
The \defnx{point of undefinition}{macro!point of undefinition}
885892
of a macro definition within a translation unit
886893
is the first point at which a \tcode{\#undef} directive naming the macro occurs
887894
after its point of definition, or the first point
888-
of macro import of a translation unit containing a point of undefinition for the
895+
of macro import of a header unit containing a point of undefinition for the
889896
macro definition, whichever (if any) occurs first.
890897
\end{itemize}
891898

@@ -926,8 +933,12 @@
926933
\end{codeblocktu}
927934

928935
\begin{codeblocktu}{Importable header \tcode{"d.h"}}
929-
import "a.h"; // point of definition of \#1, \#2, and \#3, point of undefinition of \#1 in \tcode{"d.h"}
930936
import "c.h"; // point of definition of \#4 and \#5 in \tcode{"d.h"}
937+
\end{codeblocktu}
938+
939+
\begin{codeblocktu}{Importable header \tcode{"e.h"}}
940+
import "a.h"; // point of definition of \#1, \#2, and \#3, point of undefinition of \#1 in \tcode{"e.h"}
941+
import "d.h"; // point of definition of \#4 and \#5 in \tcode{"e.h"}
931942
int a = Y; // OK, active macro definitions \#2 and \#4 are valid redefinitions
932943
int c = Z; // error: active macro definitions \#3 and \#5 are not valid redefinitions of \tcode{Z}
933944
\end{codeblocktu}

0 commit comments

Comments
 (0)