C++ Logo

sg15

Advanced search

Re: [SG15] [isocpp-modules] Determining identity like #pragma once

From: Tom Honermann <tom_at_[hidden]>
Date: Wed, 10 Jul 2019 13:18:44 -0400
On 7/10/19 1:00 PM, Gabriel Dos Reis via Modules wrote:
>
>> On Jul 10, 2019, at 6:27 AM, Bryce Adelstein Lelbach aka wash <brycelelbach_at_[hidden]> wrote:
>>
>> On Wed, Jul 10, 2019 at 2:48 AM Gabriel Dos Reis via SG15
>> <sg15_at_[hidden]> wrote:
>>> Also, we should note that import and #include of the same file can lead to unexpected results, so we need both clarifications and recommendations there for users.
>> Why should this lead to unexpected results?
>>
>> Suppose I have:
>>
>> #include <foo>
>> import <foo>;
> To illustrate the concern, let me further add that the header <foo> has include guard and all that.
>
> The #include copy-n-pastes the content of foo in the current translation - including of course any definitions. The import makes available any declaration/definition from the translation unit of foo. The program ends up with multiple definitions (at link time at least).

This doesn't sound correct to me.

For <foo> to be importable at all implies, to me, that the
implementation must be aware (somehow) that <foo> designates an
importable header. In other words, in this scenario, no copy-n-paste
inclusion occurs.

[module.import]p5 (http://eel.is/c++draft/module.import#5):

... An importable header is a member of an implementation-defined set of
headers ...

Tom.

Received on 2019-07-10 12:20:39