RE: Empty export {}

104 views
Skip to first unread message

Gabriel Dos Reis

unread,
Nov 2, 2016, 8:17:24 PM11/2/16
to mod...@isocpp.org
Sending a second time as the mailer on my phone decided to send the message not to the list.


-------- Original message --------
From: Gabriel Dos Reis <g...@microsoft.com>
Date: 11/2/16 5:08 PM (GMT-08:00)
To: Dwayne Robinson <dwa...@microsoft.com>
Subject: RE: Empty export {}

The compiler error is consistent with the spec. The notation  "export {}" does not introduce any form of scope and shouldn't be tought of as empty namespace or empty blocks or any scope construct.

It is purely a convenience to group non-empty collection of export declarations.

In the scenario below, the code is more readable if you put the export with the declaration being conditionally exported.


-------- Original message --------
From: Dwayne Robinson <dwa...@microsoft.com>
Date: 11/2/16 5:01 PM (GMT-08:00)
To: Gabriel Dos Reis <g...@microsoft.com>
Subject: Empty export {}

Any empty export clause should be a nop rather than a compile error, which would be consistent with {namespaces, local scope, void functions} which all allow empty braces. Depending on project configuration, you may end up with an empty clause.

 

error C2059: syntax error: '}'

 

e.g.:

 

export

{

#ifndef _DEBUG

    class DebugHelper ...

#endif

 

#if PROJECT_CONFIG_USE_CAT

    class Cat ...

#endif

 

#if PROJECT_CONFIG_USE_DOG

    class Dog ...

#endif

}

 

 

(yes, I’m merrily mixing the preprocessor with modules, but these are global defines for the whole project.)

Gabriel Dos Reis

unread,
Nov 2, 2016, 8:26:26 PM11/2/16
to mod...@isocpp.org
Arg, wrong mailing list. Please, ignore.

Jens Maurer

unread,
Nov 3, 2016, 2:15:32 PM11/3/16
to mod...@isocpp.org
On 11/03/2016 01:17 AM, 'Gabriel Dos Reis' via SG2 - Modules wrote:
> The compiler error is consistent with the spec. The notation "export {}" does not introduce any form of scope and shouldn't be tought of as empty namespace or empty blocks or any scope construct.
>
> It is purely a convenience to group non-empty collection of export declarations.

That seems inconsistent with what we do for linkage-specifications,
i.e. language linkage such as 'extern "C" { ... }'.

There's no new scope here, either, yet we do allow empty contents
as per the grammar in 7.5p2.

Please open an issue so that this can be discussed in a wider
audience.

Jens


> In the scenario below, the code is more readable if you put the export with the declaration being conditionally exported.
>
>
> -------- Original message --------
> From: Dwayne Robinson <dwa...@microsoft.com>
> Date: 11/2/16 5:01 PM (GMT-08:00)
> To: Gabriel Dos Reis <g...@microsoft.com>
> Subject: Empty export {}
>
> Any empty export clause should be a nop rather than a compile error, which would be consistent with {namespaces, local scope, void functions} which all allow empty braces. Depending on project configuration, you may end up with an empty clause.
>
>
>
> error C2059: syntax error: '}'
>
>
>
> e.g.:
>
> …
>
>
>
> export
>
> {
>
> #ifndef_DEBUG
>
> classDebugHelper ...
>
> #endif
>
>
>
> #ifPROJECT_CONFIG_USE_CAT
>
> classCat ...
>
> #endif
>
>
>
> #ifPROJECT_CONFIG_USE_DOG
>
> classDog ...
>
> #endif
>
> }
>
>
>
> …
>
>
>
> (yes, I’m merrily mixing the preprocessor with modules, but these are global defines for the whole project.)
>
> --
> You received this message because you are subscribed to the Google Groups "SG2 - Modules" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to modules+u...@isocpp.org <mailto:modules+u...@isocpp.org>.
> To post to this group, send email to mod...@isocpp.org <mailto:mod...@isocpp.org>.
> Visit this group at https://groups.google.com/a/isocpp.org/group/modules/.

Reply all
Reply to author
Forward
0 new messages