Topic: Attributes on using-declarations
Author: Sean Hunt <rideau3@gmail.com>
Date: Fri, 14 Aug 2009 12:44:23 CST Raw View
What's the rationale behind not allowing attributes on using-
declarations? Is it just that no compiler currently uses them? If so,
that seems horribly shortsighted - for instance, there's no real
reason someone might not want to implement a version of GCC's strong
using attribute on a declaration instead of a directive. If someone
did, they would have to extend the syntax, which is bad.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Kenneth 'Bessarion' Boyd" <zaimoni@zaimoni.com>
Date: Sat, 15 Aug 2009 13:37:39 CST Raw View
On Aug 14, 1:44 pm, Sean Hunt <ride...@gmail.com> wrote:
> What's the rationale behind not allowing attributes on using-
> declarations? Is it just that no compiler currently uses them?
While waiting for someone who actually knows: Which C++0X draft(s)
disallows attributes on using-declaration?
The publicly available n2914's 7.3.4 [namespace.udir], where the
syntax of using directives is defined, explicitly allows an optional
attribute-specifier that appertains to the using declaration itself.
So there's nothing preventing implementation-defined attributes from
applying to using directives. (E.g., your example that emulates GCC's
strong attribute. I'd be tempted to restructure to use C++0X inline
namespaces first).
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Joe Smith" <unknown_kev_cat@hotmail.com>
Date: Sun, 16 Aug 2009 01:47:58 CST Raw View
"Kenneth 'Bessarion' Boyd" <zaimoni@zaimoni.com> wrote in message
news:7722de48-799c-443f-b63a-c40cd3ef882b@j21g2000yqe.googlegroups.com...
> On Aug 14, 1:44 pm, Sean Hunt <ride...@gmail.com> wrote:
>> What's the rationale behind not allowing attributes on using-
>> declarations? Is it just that no compiler currently uses them?
>
> While waiting for someone who actually knows: Which C++0X draft(s)
> disallows attributes on using-declaration?
>
> The publicly available n2914's 7.3.4 [namespace.udir], where the
> syntax of using directives is defined, explicitly allows an optional
> attribute-specifier that appertains to the using declaration itself.
> So there's nothing preventing implementation-defined attributes from
> applying to using directives. (E.g., your example that emulates GCC's
> strong attribute. I'd be tempted to restructure to use C++0X inline
> namespaces first).
Are you confusing the using declaration with the using directive?
The language specified by N2914 allows:
[[__gcc_feature]] using namespace std;
but not
[[__gcc_feature]] using std::cout;
using [[__gcc_feature]] std::cout;
or even
using std::cout [[__gcc_feature]];
(I admit that I have not studied the attributes syntax well enough to know
which of those makes any sense, but at least one of them does.)
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: Ron <ron.natalie@gmail.com>
Date: Sun, 16 Aug 2009 01:46:08 CST Raw View
On Aug 14, 2:44 pm, Sean Hunt <ride...@gmail.com> wrote:
> What's the rationale behind not allowing attributes on using-
> declarations? Is it just that no compiler currently uses them? If so,
> that seems horribly shortsighted - for instance, there's no real
> reason someone might not want to implement a version of GCC's strong
> using attribute on a declaration instead of a directive. If someone
> did, they would have to extend the syntax, which is bad.
>
Because using affects how NAMES are looked up. Names don't
have any "attributes." It is only after a NAME is resolved that
the overloads of that name are considered. I'm not sure
what GCC's screwy extension does, but to do what you are
asking is more than just changing the using syntax, it's changing
the overall semantics of the language in a way that is seriously
at odds with the way the language works currently.
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: "Kenneth 'Bessarion' Boyd" <zaimoni@zaimoni.com>
Date: Mon, 17 Aug 2009 13:16:30 CST Raw View
On Aug 16, 2:47 am, "Joe Smith" <unknown_kev_...@hotmail.com> wrote:
> Are you confusing the using declaration with the using directive?
I chose the standard citation that matches the example he gave, not
the citation that matches what he's superficially asking about. I
should have done both.
> The language specified by N2914 allows:
> [[__gcc_feature]] using namespace std;
This is where the GCC extension attribute strong is actually used, per
online documentation: using directives. There is no GCC strong
attribute for using-declarations as of GCC 4.4.1.
> but not
>
> [[__gcc_feature]] using std::cout;
> using [[__gcc_feature]] std::cout;
> or even
> using std::cout [[__gcc_feature]];
Agreed, there is no provision (n2914 7.3.3p1, [namespace.udecl]) for
attribute-specifiers in using-declarations.
> ....
Naively (remember, waiting on an expert -- I'm not in the loop), the
problem isn't syntax, it's semantics -- and it has nothing to do with
vendor implementation extensions. Informally, the implementation of
using-declarations is the same as the implementation of typedefs, the
"renaming" is just of functions and objects rather than types. Using-
directives have the problem that they're still not "equivalent-
strength", there's more to them in implementation than just
"renaming".
Consider
using [[noreturn]] std::setbuf;
. This is a user-code modification of the declaration in cstdio, so
it informally should be just as much undefined behavior as editing
cstdio from the implementation-provided version.
It seems simpler to just head this off syntactically, rather than put
in yet another undefined behavior clause just for user code adding
attributes to declarations in the standard library via using-
directives. There's nothing to be gained in user code by allowing
this construct; the attributes can just be used on the declaration
being "renamed".
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]