On 02/15/2017 01:17 PM, Jason Merrill wrote:
On Wed, Feb 15, 2017 at 1:57 PM, Jonathan Wakely <jwakely....@gmail.com> wrote:
On 15 February 2017 at 15:53, Jason Merrill wrote:
On Sat, Feb 11, 2017 at 4:19 PM, Jonathan Wakely <jwakely....@gmail.com> wrote:
On 11 February 2017 at 20:36, Sandra Loosemore wrote:
On 02/11/2017 06:21 AM, Jonathan Wakely wrote:

On 11 February 2017 at 08:48, Gerald Pfeifer wrote:

On Fri, 10 Feb 2017, Sandra Loosemore wrote:

The documentation for -Wno-non-template-friend refers to
"non-templatized
friend functions" and "templatized functions".  I don't see the term
"templatized" used anywhere in the C++ standard.  This paragraph also
uses
"nontemplate function", which I assume refers to the same thing the C++
standard spells "non-template function".  So does "non-templatized
function"
also mean "non-template function"?  Or does it have some other meaning?


I would avoid "templatized" and believe "non-template function" is
more appropriate in your example.


Yes,

s/non-templatized/non-template/
s/nontemplate/non-template/
s/templatized function/function template/

But I wonder if that warning is even useful nowadays. The example of
"friend foo(int);" is bogus and is correctly rejected:

fr.cc:2:17: error: ISO C++ forbids declaration of ‘foo’ with no type
[-fpermissive]
     friend foo(int);
                   ^


I hadn't actually gotten that far :-) but it looks like that's an
implicit-int error unrelated to the actual purpose of this option.

This ended up on my todo list firstly because "templatized" didn't
spell-check, and secondly because the "new compiler behavior" documented in
connection with this option has existed at least since 1998 and can hardly
be considered "new" any more.  Also I think the reference to section 14.5.3
of the C++ standard is bit-rotten (it's 14.5.4 in the c++0x draft I have
handy).

I'll leave it up to the C++ experts to decide whether the option should just
be removed and the warning replaced with a hard error controlled by some
other flag.

It definitely shouldn't be turned into a hard error, the warning
complains about valid code, such as:

template<typename T> struct A {
   friend int foo(T);
};

int main() {
   A<int> a;
}

I think it warns because the meaning of that code changed, a *long*
time ago, so it's saying "if you wrote this code in the 1990s it might
do something different to what you expect."

I'm not sure how useful that warning is now, although EDG warns for it
too (with a fix-it hint that I think is bogus):

"fr.cc", line 2: warning: "int foo(T)" declares a non-template function -- add
           <> to refer to a template instance
     friend int foo(T);
                ^

That fix-it looks fine to me;

Where should I add the <> to make it valid?

If I change the example to "friend int foo<>(T);" EDG says it's not a template:

template<typename T> struct A {
   friend int foo<>(T);
};

int main() {
   A<int> a;
}

"fr.cc", line 2: error: foo is not a template
     friend int foo<>(T);

Yep, you would also need to declare the foo template earlier in the TU.

Jason


Thanks everyone for the explanations and suggestions. I've checked in the attached patch to clean this up.

-Sandra

2017-02-16  Sandra Loosemore  <san...@codesourcery.com>

	gcc/
	* doc/invoke.texi (C++ Dialect Options) [-Wno-non-template-friend]: 
	Correct terminology and de-emphasize pre-standard behavior.
Index: gcc/doc/invoke.texi
===================================================================
--- gcc/doc/invoke.texi	(revision 245524)
+++ gcc/doc/invoke.texi	(working copy)
@@ -2996,19 +2996,13 @@ But this use is not portable across diff
 @item -Wno-non-template-friend @r{(C++ and Objective-C++ only)}
 @opindex Wno-non-template-friend
 @opindex Wnon-template-friend
-Disable warnings when non-templatized friend functions are declared
-within a template.  Since the advent of explicit template specification
-support in G++, if the name of the friend is an unqualified-id (i.e.,
-@samp{friend foo(int)}), the C++ language specification demands that the
-friend declare or define an ordinary, nontemplate function.  (Section
-14.5.3).  Before G++ implemented explicit specification, unqualified-ids
-could be interpreted as a particular specialization of a templatized
-function.  Because this non-conforming behavior is no longer the default
-behavior for G++, @option{-Wnon-template-friend} allows the compiler to
-check existing code for potential trouble spots and is on by default.
-This new compiler behavior can be turned off with
-@option{-Wno-non-template-friend}, which keeps the conformant compiler code
-but disables the helpful warning.
+Disable warnings when non-template friend functions are declared
+within a template.  In very old versions of GCC that predate implementation
+of the ISO standard, declarations such as 
+@samp{friend int foo(int)}, where the name of the friend is an unqualified-id,
+could be interpreted as a particular specialization of a template
+function; the warning exists to diagnose compatibility problems, 
+and is enabled by default.
 
 @item -Wold-style-cast @r{(C++ and Objective-C++ only)}
 @opindex Wold-style-cast

Reply via email to