blob: d513da26da5d5ea4f3f078d2f35f6073783eb3d5 [file] [log] [blame]
Douglas Gregore703f2d2013-03-20 06:25:14 +00001=======
2Modules
3=======
4
5.. contents::
6 :local:
7
Sean Silva28e0def2013-03-20 18:37:42 +00008.. warning::
9 The functionality described on this page is still experimental! Please
10 try it out and send us bug reports!
11
Douglas Gregore703f2d2013-03-20 06:25:14 +000012Introduction
13============
14Most software is built using a number of software libraries, including libraries supplied by the platform, internal libraries built as part of the software itself to provide structure, and third-party libraries. For each library, one needs to access both its interface (API) and its implementation. In the C family of languages, the interface to a library is accessed by including the appropriate header files(s):
15
16.. code-block:: c
17
18 #include <SomeLib.h>
19
20The implementation is handled separately by linking against the appropriate library. For example, by passing ``-lSomeLib`` to the linker.
21
22Modules provide an alternative, simpler way to use software libraries that provides better compile-time scalability and eliminates many of the problems inherent to using the C preprocessor to access the API of a library.
23
24Problems with the Current Model
25-------------------------------
26The ``#include`` mechanism provided by the C preprocessor is a very poor way to access the API of a library, for a number of reasons:
27
28* **Compile-time scalability**: Each time a header is included, the
29 compiler must preprocess and parse the text in that header and every
30 header it includes, transitively. This process must be repeated for
31 every translation unit in the application, which involves a huge
32 amount of redundant work. In a project with *N* translation units
33 and *M* headers included in each translation unit, the compiler is
34 performing *M x N* work even though most of the *M* headers are
35 shared among multiple translation units. C++ is particularly bad,
36 because the compilation model for templates forces a huge amount of
37 code into headers.
38
39* **Fragility**: ``#include`` directives are treated as textual
40 inclusion by the preprocessor, and are therefore subject to any
41 active macro definitions at the time of inclusion. If any of the
42 active macro definitions happens to collide with a name in the
43 library, it can break the library API or cause compilation failures
44 in the library header itself. For an extreme example,
45 ``#define std "The C++ Standard"`` and then include a standard
46 library header: the result is a horrific cascade of failures in the
47 C++ Standard Library's implementation. More subtle real-world
48 problems occur when the headers for two different libraries interact
49 due to macro collisions, and users are forced to reorder
50 ``#include`` directives or introduce ``#undef`` directives to break
51 the (unintended) dependency.
52
53* **Conventional workarounds**: C programmers have
54 adopted a number of conventions to work around the fragility of the
55 C preprocessor model. Include guards, for example, are required for
56 the vast majority of headers to ensure that multiple inclusion
57 doesn't break the compile. Macro names are written with
58 ``LONG_PREFIXED_UPPERCASE_IDENTIFIERS`` to avoid collisions, and some
59 library/framework developers even use ``__underscored`` names
60 in headers to avoid collisions with "normal" names that (by
61 convention) shouldn't even be macros. These conventions are a
62 barrier to entry for developers coming from non-C languages, are
63 boilerplate for more experienced developers, and make our headers
64 far uglier than they should be.
65
66* **Tool confusion**: In a C-based language, it is hard to build tools
67 that work well with software libraries, because the boundaries of
68 the libraries are not clear. Which headers belong to a particular
69 library, and in what order should those headers be included to
70 guarantee that they compile correctly? Are the headers C, C++,
71 Objective-C++, or one of the variants of these languages? What
72 declarations in those headers are actually meant to be part of the
73 API, and what declarations are present only because they had to be
74 written as part of the header file?
75
76Semantic Import
77---------------
78Modules improve access to the API of software libraries by replacing the textual preprocessor inclusion model with a more robust, more efficient semantic model. From the user's perspective, the code looks only slightly different, because one uses an ``import`` declaration rather than a ``#include`` preprocessor directive:
79
80.. code-block:: c
81
82 import std.io; // pseudo-code; see below for syntax discussion
83
84However, this module import behaves quite differently from the corresponding ``#include <stdio.h>``: when the compiler sees the module import above, it loads a binary representation of the ``std.io`` module and makes its API available to the application directly. Preprocessor definitions that precede the import declaration have no impact on the API provided by ``std.io``, because the module itself was compiled as a separate, standalone module. Additionally, any linker flags required to use the ``std.io`` module will automatically be provided when the module is imported [#]_
85This semantic import model addresses many of the problems of the preprocessor inclusion model:
86
87* **Compile-time scalability**: The ``std.io`` module is only compiled once, and importing the module into a translation unit is a constant-time operation (independent of module system). Thus, the API of each software library is only parsed once, reducing the *M x N* compilation problem to an *M + N* problem.
88
89* **Fragility**: Each module is parsed as a standalone entity, so it has a consistent preprocessor environment. This completely eliminates the need for ``__underscored`` names and similarly defensive tricks. Moreover, the current preprocessor definitions when an import declaration is encountered are ignored, so one software library can not affect how another software library is compiled, eliminating include-order dependencies.
90
91* **Tool confusion**: Modules describe the API of software libraries, and tools can reason about and present a module as a representation of that API. Because modules can only be built standalone, tools can rely on the module definition to ensure that they get the complete API for the library. Moreover, modules can specify which languages they work with, so, e.g., one can not accidentally attempt to load a C++ module into a C program.
92
93Problems Modules Do Not Solve
94-----------------------------
95Many programming languages have a module or package system, and because of the variety of features provided by these languages it is important to define what modules do *not* do. In particular, all of the following are considered out-of-scope for modules:
96
97* **Rewrite the world's code**: It is not realistic to require applications or software libraries to make drastic or non-backward-compatible changes, nor is it feasible to completely eliminate headers. Modules must interoperate with existing software libraries and allow a gradual transition.
98
99* **Versioning**: Modules have no notion of version information. Programmers must still rely on the existing versioning mechanisms of the underlying language (if any exist) to version software libraries.
100
101* **Namespaces**: Unlike in some languages, modules do not imply any notion of namespaces. Thus, a struct declared in one module will still conflict with a struct of the same name declared in a different module, just as they would if declared in two different headers. This aspect is important for backward compatibility, because (for example) the mangled names of entities in software libraries must not change when introducing modules.
102
Douglas Gregorbb1c7e32013-03-20 17:11:13 +0000103* **Binary distribution of modules**: Headers (particularly C++ headers) expose the full complexity of the language. Maintaining a stable binary module format across architectures, compiler versions, and compiler vendors is technically infeasible.
Douglas Gregore703f2d2013-03-20 06:25:14 +0000104
105Using Modules
106=============
107To enable modules, pass the command-line flag ``-fmodules`` [#]_. This will make any modules-enabled software libraries available as modules as well as introducing any modules-specific syntax. Additional command-line parameters are described later.
108
109Includes as Imports
110-------------------
111The primary user-level feature of modules is the import operation, which provides access to the API of software libraries. However, Clang does not provide a specific syntax for importing modules within the language itself [#]_. Instead, Clang translates ``#include`` directives into the corresponding module import. For example, the include directive
112
113.. code-block:: c
114
115 #include <stdio.h>
116
Douglas Gregorbb1c7e32013-03-20 17:11:13 +0000117will be automatically mapped to an import of the module ``std.io``. Even with specific ``import`` syntax in the language, this particular feature is important for both adoption and backward compatibility: automatic translation of ``#include`` to ``import`` allows an application to get the benefits of modules (for all modules-enabled libraries) without any changes to the application itself. Thus, users can easily use modules with one compiler while falling back to the preprocessor-inclusion mechanism with other compilers.
Douglas Gregore703f2d2013-03-20 06:25:14 +0000118
119Module Maps
120-----------
121The crucial link between modules and headers is described by a *module map*, which describes how a collection of existing headers maps on to the (logical) structure of a module. For example, one could imagine a module ``std`` covering the C standard library. Each of the C standard library headers (``<stdio.h>``, ``<stdlib.h>``, ``<math.h>``, etc.) would contribute to the ``std`` module, by placing their respective APIs into the corresponding submodule (``std.io``, ``std.lib``, ``std.math``, etc.). Having a list of the headers that are part of the ``std`` module allows the compiler to build the ``std`` module as a standalone entity, and having the mapping from header names to (sub)modules allows the automatic translation of ``#include`` directives to module imports.
122
123Module maps are specified as separate files (each named ``module.map``) alongside the headers they describe, which allows them to be added to existing software libraries without having to change the library headers themselves (in most cases [#]_). The actual `Module Map Language`_ is described in a later section.
124
125Compilation Model
126-----------------
127The binary representation of modules is automatically generated by the compiler on an as-needed basis. When a module is imported (e.g., by an ``#include`` of one of the module's headers), the compiler will spawn a second instance of itself, with a fresh preprocessing context [#]_, to parse just the headers in that module. The resulting Abstract Syntax Tree (AST) is then persisted into the binary representation of the module that is then loaded into translation unit where the module import was encountered.
128
129The binary representation of modules is persisted in the *module cache*. Imports of a module will first query the module cache and, if a binary representation of the required module is already available, will load that representation directly. Thus, a module's headers will only be parsed once per language configuration, rather than once per translation unit that uses the module.
130
131Modules maintain references to each of the headers that were part of the module build. If any of those headers changes, or if any of the modules on which a module depends change, then the module will be (automatically) recompiled. The process should never require any user intervention.
132
133Command-line parameters
134-----------------------
135``-fmodules``
136 Enable the modules feature (EXPERIMENTAL).
137
138``-fcxx-modules``
139 Enable the modules feature for C++ (EXPERIMENTAL and VERY BROKEN).
140
141``-fmodules-cache-path=<directory>``
142 Specify the path to the modules cache. If not provided, Clang will select a system-appropriate default.
143
144``-f[no-]modules-autolink``
145 Enable of disable automatic linking against the libraries associated with imported modules.
146
147``-fmodules-ignore-macro=macroname``
148 Instruct modules to ignore the named macro when selecting an appropriate module variant. Use this for macros defined on the command line that don't affect how modules are built, to improve sharing of compiled module files.
149
150Module Map Language
151===================
Douglas Gregore703f2d2013-03-20 06:25:14 +0000152
Douglas Gregorde0beaa2013-03-22 06:21:35 +0000153The module map language describes the mapping from header files to the
154logical structure of modules. To enable support for using a library as
155a module, one must write a ``module.map`` file for that library. The
156``module.map`` file is placed alongside the header files themselves,
157and is written in the module map language described below.
158
159As an example, the module map file for the C standard library might look a bit like this:
160
161.. parsed-literal::
162
163 module std [system] {
164 module complex {
165 header "complex.h"
166 export *
167 }
168
169 module ctype {
170 header "ctype.h"
171 export *
172 }
173
174 module errno {
175 header "errno.h"
176 header "sys/errno.h"
177 export *
178 }
179
180 module fenv {
181 header "fenv.h"
182 export *
183 }
184
185 // ...more headers follow...
186 }
187
188Here, the top-level module ``std`` encompasses the whole C standard library. It has a number of submodules containing different parts of the standard library: ``complex`` for complex numbers, ``ctype`` for character types, etc. Each submodule lists one of more headers that provide the contents for that submodule. Finally, the ``export *`` command specifies that anything included by that submodule will be automatically re-exported.
189
190Lexical Structure
191-----------------
192Module map files use a simplified form of the C99 lexer, with the same rules for identifiers, tokens, string literals, ``/* */`` and ``//`` comments. The module map language has the following reserved words; all other C identifiers are valid identifiers.
193
194.. parsed-literal::
195
196 ``config_macros`` ``export`` ``module``
197 ``conflict`` ``framework`` ``requires``
198 ``exclude`` ``header`` ``umbrella``
199 ``explicit`` ``link``
200
201Module Map Files
202----------------
203A module map file consists of a series of module declarations:
204
205.. parsed-literal::
206
207 *module-map-file*:
208 *module-declaration**
209
210Within a module map file, modules are referred to by a *module-id*, which uses periods to separate each part of a module's name:
211
212.. parsed-literal::
213
214 *module-id*:
215 *identifier* (',' *identifier*)*
216
217Module Declarations
218-------------------
219A module declaration describes a module, including the headers that contribute to that module, its submodules, and other aspects of the module.
220
221.. parsed-literal::
222
223 *module-declaration*:
224 ``explicit``:sub:`opt` ``framework``:sub:`opt` ``module`` *module-id* *attributes*:sub:`opt` '{' *module-member** '}'
225
226The *module-id* should consist of only a single *identifier*, which provides the name of the module being defined. Each module shall have a single definition.
227
228The ``explicit`` qualifier can only be applied to a submodule, i.e., a module that is nested within another module. The contents of explicit submodules are only made available when the submodule itself was explicitly named in an import declaration or was re-exported from an imported module.
229
230The ``framework`` qualifier specifies that this module corresponds to a Darwin-style framework. A Darwin-style framework (used primarily on Mac OS X and iOS) is contained entirely in directory ``Name.framework``, where ``Name`` is the name of the framework (and, therefore, the name of the module). That directory has the following layout:
231
232.. parsed-literal::
233
234 Name.framework/
235 module.map Module map for the framework
236 Headers/ Subdirectory containing framework headers
237 Frameworks/ Subdirectory containing embedded frameworks
238 Resources/ Subdirectory containing additional resources
239 Name Symbolic link to the shared library for the framework
240
241The ``system`` attribute specifies that the module is a system module. When a system module is rebuilt, all of the module's header will be considered system headers, which suppresses warnings. This is equivalent to placing ``#pragma GCC system_header`` in each of the module's headers. The form of attributes is described in the section Attributes_, below.
242
243Modules can have a number of different kinds of members, each of which is described below:
244
245.. parsed-literal:
246
247 *module-member*:
248 *requires-declaration*
249 *header-declaration*
250 *umbrella-dir-declaration*
251 *submodule-declaration*
252 *export-declaration*
253 *link-declaration*
254 *config-macros-declaration*
255 *conflict-declaration*
256
257Requires Declaration
258~~~~~~~~~~~~~~~~~~~~
259A *requires-declaration* specifies the requirements that an importing translation unit must satisfy to use the module.
260
261.. parsed-literal::
262
263 *requires-declaration*:
264 ``requires`` *feature-list*
265
266 *feature-list*:
267 *identifier* (',' *identifier*)*
268
269The requirements clause allows specific modules or submodules to specify that they are only accessible with certain language dialects or on certain platforms. The feature list is a set of identifiers, defined below. If any of the features is not available in a given translation unit, that translation unit shall not import the module.
270
271The following features are defined:
272
273altivec
274 The target supports AltiVec.
275
276blocks
277 The "blocks" language feature is available.
278
279cplusplus
280 C++ support is available.
281
282cplusplus11
283 C++11 support is available.
284
285objc
286 Objective-C support is available.
287
288objc_arc
289 Objective-C Automatic Reference Counting (ARC) is available
290
291opencl
292 OpenCL is available
293
294tls
295 Thread local storage is available.
296
297*target feature*
298 A specific target feature (e.g., ``sse4``, ``avx``, ``neon``) is available.
299
300
301**Example**: The ``std`` module can be extended to also include C++ and C++11 headers using a *requires-declaration*:
302
303.. parsed-literal::
304
305 module std {
306 // C standard library...
307
308 module vector {
309 requires cplusplus
310 header "vector"
311 }
312
313 module type_traits {
314 requires cplusplus11
315 header "type_traits"
316 }
317 }
318
319Header Declaration
320~~~~~~~~~~~~~~~~~~
321A header declaration specifies that a particular header is associated with the enclosing module.
322
323.. parsed-literal::
324
325 *header-declaration*:
326 ``umbrella``:sub:`opt` ``header`` *string-literal*
327 ``exclude`` ``header`` *string-literal*
328
329A header declaration that does not contain ``exclude`` specifies a header that contributes to the enclosing module. Specifically, when the module is built, the named header will be parsed and its declarations will be (logically) placed into the enclosing submodule.
330
331A header with the ``umbrella`` specifier is called an umbrella header. An umbrella header includes all of the headers within its directory (and any subdirectories), and is typically used (in the ``#include`` world) to easily access the full API provided by a particular library. With modules, an umbrella header is a convenient shortcut that eliminates the need to write out ``header`` declarations for every library header. A given directory can only contain a single umbrella header.
332
333.. note::
334 Any headers not included by the umbrella header should have
335 explicit ``header`` declarations. Use the
336 ``-Wincomplete-umbrella`` warning option to ask Clang to complain
337 about headers not covered by the umbrella header or the module map.
338
339A header with the ``exclude`` specifier is excluded from the module. It will not be included when the module is built, nor will it be considered to be part of the module.
340
341**Example**: The C header ``assert.h`` is an excellent candidate for an excluded header, because it is meant to be included multiple times (possibly with different ``NDEBUG`` settings).
342
343.. parsed-literal::
344
345 module std [system] {
346 exclude header "assert.h"
347 }
348
349A given header shall not be referenced by more than one *header-declaration*.
350
351Umbrella Directory Declaration
352~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
353An umbrella directory declaration specifies that all of the headers in the specified directory should be included within the module.
354
355.. parsed-literal::
356
357 *umbrella-dir-declaration*:
358 ``umbrella`` *string-literal*
359
360The *string-literal* refers to a directory. When the module is built, all of the header files in that directory (and its subdirectories) are included in the module.
361
362An *umbrella-dir-declaration* shall not refer to the same directory as the location of an umbrella *header-declaration*. In other words, only a single kind of umbrella can be specified for a given directory.
363
364.. note::
365
366 Umbrella directories are useful for libraries that have a large number of headers but do not have an umbrella header.
367
368
369Submodule Declaration
370~~~~~~~~~~~~~~~~~~~~~
371Submodule declarations describe modules that are nested within their enclosing module.
372
373.. parsed-literal::
374
375 *submodule-declaration*:
376 *module-declaration*
377 *inferred-submodule-declaration*
378
379A *submodule-declaration* that is a *module-declaration* is a nested module. If the *module-declaration* has a ``framework`` specifier, the enclosing module shall have a ``framework`` specifier; the submodule's contents shall be contained within the subdirectory ``Frameworks/SubName.framework``, where ``SubName`` is the name of the submodule.
380
381A *submodule-declaration* that is an *inferred-submodule-declaration* describes a set of submodules that correspond to any headers that are part of the module but are not explicitly described by a *header-declaration*.
382
383.. parsed-literal::
384
385 *inferred-submodule-declaration*:
386 ``explicit``:sub:`opt` ``framework``:sub:`opt` ``module`` '*' *attributes*:sub:`opt` '{' *inferred-submodule-member** '}'
387
388 *inferred-submodule-member*:
389 ``export`` '*'
390
391A module containing an *inferred-submodule-declaration* shall have either an umbrella header or an umbrella directory. The headers to which the *inferred-submodule-declaration* applies are exactly those headers included by the umbrella header (transitively) or included in the module because they reside within the umbrella directory (or its subdirectories).
392
393For each header included by the umbrella header or in the umbrella directory that is not named by a *header-declaration*, a module declaration is implicitly generated from the *inferred-submodule-declaration*. The module will:
394
395* Have the same name as the header (without the file extension)
396* Have the ``explicit`` specifier, if the *inferred-submodule-declaration* has the ``explicit`` specifier
397* Have the ``framework`` specifier, if the
398 *inferred-submodule-declaration* has the ``framework`` specifier
399* Have the attributes specified by the \ *inferred-submodule-declaration*
400* Contain a single *header-declaration* naming that header
401* Contain a single *export-declaration* ``export *``, if the \ *inferred-submodule-declaration* contains the \ *inferred-submodule-member* ``export *``
402
403**Example**: If the subdirectory "MyLib" contains the headers ``A.h`` and ``B.h``, then the following module map:
404
405.. parsed-literal::
406
407 module MyLib {
408 umbrella "MyLib"
409 explicit module * {
410 export *
411 }
412 }
413
414is equivalent to the (more verbose) module map:
415
416.. parsed-literal::
417
418 module MyLib {
419 explicit module A {
420 header "A.h"
421 export *
422 }
423
424 explicit module B {
425 header "B.h"
426 export *
427 }
428 }
429
430Export Declaration
431~~~~~~~~~~~~~~~~~~
432An *export-declaration* specifies which imported modules will automatically be re-exported as part of a given module's API.
433
434.. parsed-literal::
435
436 *export-declaration*:
437 ``export`` *wildcard-module-id*
438
439 *wildcard-module-id*:
440 *identifier*
441 '*'
442 *identifier* '.' *wildcard-module-id*
443
444The *export-declaration* names a module or a set of modules that will be re-exported to any translation unit that imports the enclosing module. Each imported module that matches the *wildcard-module-id* up to, but not including, the first ``*`` will be re-exported.
445
446**Example**:: In the following example, importing ``MyLib.Derived`` also provides the API for ``MyLib.Base``:
447
448.. parsed-literal::
449
450 module MyLib {
451 module Base {
452 header "Base.h"
453 }
454
455 module Derived {
456 header "Derived.h"
457 export Base
458 }
459 }
460
461Note that, if ``Derived.h`` includes ``Base.h``, one can simply use a wildcard export to re-export everything ``Derived.h`` includes:
462
463.. parsed-literal::
464
465 module MyLib {
466 module Base {
467 header "Base.h"
468 }
469
470 module Derived {
471 header "Derived.h"
472 export *
473 }
474 }
475
476.. note::
477
478 The wildcard export syntax ``export *`` re-exports all of the
479 modules that were imported in the actual header file. Because
480 ``#include`` directives are automatically mapped to module imports,
481 ``export *`` provides the same transitive-inclusion behavior
482 provided by the C preprocessor, e.g., importing a given module
483 implicitly imports all of the modules on which it depends.
484 Therefore, liberal use of ``export *`` provides excellent backward
485 compatibility for programs that rely on transitive inclusion (i.e.,
486 all of them).
487
488Link Declaration
489~~~~~~~~~~~~~~~~
490A *link-declaration* specifies a library or framework against which a program should be linked if the enclosing module is imported in any translation unit in that program.
491
492.. parsed-literal::
493
494 *link-declaration*:
495 ``link`` ``framework``:sub:`opt` *string-literal*
496
497The *string-literal* specifies the name of the library or framework against which the program should be linked. For example, specifying "clangBasic" would instruct the linker to link with ``-lclangBasic`` for a Unix-style linker.
498
499A *link-declaration* with the ``framework`` specifies that the linker should link against the named framework, e.g., with ``-framework MyFramework``.
500
501.. note::
502
503 Automatic linking with the ``link`` directive is not yet widely
504 implemented, because it requires support from both the object file
505 format and the linker. The notion is similar to Microsoft Visual
506 Studio's ``#pragma comment(lib...)``.
507
508Configation Macros Declaration
509~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
510The *config-macros-declaration* specifies the set of configuration macros that have an effect on the the API of the enclosing module.
511
512.. parsed-literal::
513
514 *config-macros-declaration*:
515 ``config_macros`` *attributes*:sub:`opt` *config-macro-list*:sub:`opt`
516
517 *config-macro-list*:
518 *identifier* (',' *identifier*)*
519
520Each *identifier* in the *config-macro-list* specifies the name of a macro. The compiler is required to maintain different variants of the given module for differing definitions of any of the named macros.
521
522A *config-macros-declaration* shall only be present on a top-level module, i.e., a module that is not nested within an enclosing module.
523
524The ``exhaustive`` attribute specifies that the list of macros in the *config-macros-declaration* is exhaustive, meaning that no other macro definition is intended to have an effect on the API of that module.
525
526.. note::
527
528 The ``exhaustive`` attribute implies that any macro definitions
529 for macros not listed as configuration macros should be ignored
530 completely when building the module. As an optimization, the
531 compiler could reduce the number of unique module variants by not
532 considering these non-configuration macros. This optimization is not
533 yet implemented in Clang.
534
535A translation unit shall not import the same module under different definitions of the configuration macros.
536
537.. note::
538
539 Clang implements a weak form of this requirement: the definitions
540 used for configuration macros are fixed based on the definitions
541 provided by the command line. If an import occurs and the definition
542 of any configuration macro has changed, the compiler will produce a
543 warning (under the control of ``-Wconfig-macros``).
544
545**Example:** A logging library might provide different API (e.g., in the form of different definitions for a logging macro) based on the ``NDEBUG`` macro setting:
546
547.. parsed-literal::
548
549 module MyLogger {
550 umbrella header "MyLogger.h"
551 config_macros [exhaustive] NDEBUG
552 }
553
554Conflict Declarations
555~~~~~~~~~~~~~~~~~~~~~
556A *conflict-declaration* describes a case where the presence of two different modules in the same translation unit is likely to cause a problem. For example, two modules may provide similar-but-incompatible functionality.
557
558.. parsed-literal::
559
560 *conflict-declaration*:
561 ``conflict`` *module-id* ',' *string-literal*
562
563The *module-id* of the *conflict-declaration* specifies the module with which the enclosing module conflicts. The specified module shall not have been imported in the translation unit when the enclosing module is imported.
564
565The *string-literal* provides a message to be provided as part of the compiler diagnostic when two modules conflict.
566
567.. note::
568
569 Clang emits a warning (under the control of ``-Wmodule-conflict``)
570 when a module conflict is discovered.
571
572**Example:**
573
574.. parsed-literal::
575
576 module Conflicts {
577 explicit module A {
578 header "conflict_a.h"
579 conflict B, "we just don't like B"
580 }
581
582 module B {
583 header "conflict_b.h"
584 }
585 }
586
587
588Attributes
589----------
590Attributes are used in a number of places in the grammar to describe specific behavior of other declarations. The format of attributes is fairly simple.
591
592.. parsed-literal::
593
594 *attributes*:
595 *attribute* *attributes*:sub:`opt`
596
597 *attribute*:
598 '[' *identifier* ']'
599
600Any *identifier* can be used as an attribute, and each declaration specifies what attributes can be applied to it.
601
602Where To Learn More About Modules
603=================================
604The Clang source code provides additional information about modules:
605
606``clang/lib/Headers/module.map``
607 Module map for Clang's compiler-specific header files.
608
609``clang/test/Modules/``
610 Tests specifically related to modules functionality.
611
612PCHInternals_
613 Information about the serialized AST format used for precompiled headers and modules.
Douglas Gregore703f2d2013-03-20 06:25:14 +0000614
615.. [#] Automatic linking against the libraries of modules requires specific linker support, which is not widely available.
616
617.. [#] Modules are only available in C and Objective-C; a separate flag ``-fcxx-modules`` enables modules support for C++, which is even more experimental and broken.
618
619.. [#] The ``import modulename;`` syntax described earlier in the document is a straw man proposal. Actual syntax will be pursued within the C++ committee and implemented in Clang.
620
621.. [#] There are certain anti-patterns that occur in headers, particularly system headers, that cause problems for modules.
622
623.. [#] The preprocessing context in which the modules are parsed is actually dependent on the command-line options provided to the compiler, including the language dialect and any ``-D`` options. However, the compiled modules for different command-line options are kept distinct, and any preprocessor directives that occur within the translation unit are ignored.
Douglas Gregorde0beaa2013-03-22 06:21:35 +0000624
625.. _PCHInternals: PCHInternals.html
626