public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* questions about cv-qualifier for function and references
@ 2010-12-02  4:52 zhang qingshan
  2010-12-02  9:19 ` Jonathan Wakely
  0 siblings, 1 reply; 2+ messages in thread
From: zhang qingshan @ 2010-12-02  4:52 UTC (permalink / raw)
  To: gcc-help

std(N3126) 8.3.2/1 says that:

Cv-qualified references are ill-formed except when the cv-qualifiers
are introduced through
the use of a typedef (7.1.3) or of a template type argument (14.3), in
which case the cv-qualifiers are ignored.

Why the following code compiled failed on GCC 4.5.0 ?
  template <typename T> void foo (T const &);
  void baz ();
  foo (baz);

while
 template <typename T> void foo (T const &);
 void baz ();
 void Test() {
   foo (baz);
 }

successfully. Really wired.

another question is: what is cv-qualifier reference ? Your guys told me that:
const int &m; is not a cv-qualifier reference. Could you give me an
example on the cv-qualifier reference ? Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: questions about cv-qualifier for function and references
  2010-12-02  4:52 questions about cv-qualifier for function and references zhang qingshan
@ 2010-12-02  9:19 ` Jonathan Wakely
  0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Wakely @ 2010-12-02  9:19 UTC (permalink / raw)
  To: zhang qingshan; +Cc: gcc-help

On 2 December 2010 04:52, zhang qingshan wrote:
> std(N3126) 8.3.2/1 says that:
>
> Cv-qualified references are ill-formed except when the cv-qualifiers
> are introduced through
> the use of a typedef (7.1.3) or of a template type argument (14.3), in
> which case the cv-qualifiers are ignored.
>
> Why the following code compiled failed on GCC 4.5.0 ?
>  template <typename T> void foo (T const &);
>  void baz ();
>  foo (baz);

you can't call a function at namespace scope
This is the same as:

void foo() { }
foo();

The template and the reference has nothing to do with it.

> while
>  template <typename T> void foo (T const &);
>  void baz ();
>  void Test() {
>   foo (baz);
>  }
>
> successfully. Really wired.

No, that's completely normal, at function scope you can call another function.
Like:
void foo() { }
void bar() {
  foo();
}

> another question is: what is cv-qualifier reference ? Your guys told me that:
> const int &m; is not a cv-qualifier reference. Could you give me an
> example on the cv-qualifier reference ? Thanks.

int i = 0;
int& const cref = i;   // error - cannot have cv-qualified reference

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2010-12-02  9:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-02  4:52 questions about cv-qualifier for function and references zhang qingshan
2010-12-02  9:19 ` Jonathan Wakely

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).