From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10664 invoked by alias); 7 Oct 2014 13:57:04 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 10651 invoked by uid 89); 7 Oct 2014 13:57:04 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_00,T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 X-HELO: postina.bo.infn.it Received: from postina.bo.infn.it (HELO postina.bo.infn.it) (131.154.11.1) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Tue, 07 Oct 2014 13:57:02 +0000 Received: from pamina.bo.infn.it (pamina.bo.infn.it [131.154.10.143]) (authenticated bits=0) by postina.bo.infn.it (8.14.5/8.14.5) with ESMTP id s97DuulO007970 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES128-SHA bits=128 verify=NO) for ; Tue, 7 Oct 2014 15:56:56 +0200 Message-ID: <5433F137.8050008@bo.infn.it> Date: Tue, 07 Oct 2014 13:57:00 -0000 From: Graziano Servizi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26.1 MIME-Version: 1.0 To: gcc-help@gcc.gnu.org Subject: Question Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-SW-Source: 2014-10/txt/msg00043.txt.bz2 I read in the 3.4.1.9 clause of the C++11 standard: Name lookup for a name used in the definition of a friend function (11.3) defined inline in the class granting friendship shall proceed as described for lookup in member function definitions. If the friend function is not defined in the class granting friendship, name lookup in the friend function definition shall proceed as described for lookup in namespace member function definitions. Later, in the 11.3.6 clause I found: A function can be defined in a friend declaration of a class if and only if the class is a non-local class (9.8), the function name is unqualified, and the function has namespace scope. [ Example: class M { friend void f() { } // definition of global f, a friend of M, // not the definition of a member function }; — end example ] So, if I have well understood I could write such a short code: # include class P { friend void friend_inline() {std :: cout << P :: Name << ' ' << p << '\n';} static constexpr int Name = 20; static constexpr double p = 12.5; }; int main() { P p; // how can I call friend_inline ? } which indeed is compiled by 4.8.3 g++ compiler. But the question is in the comment: I tried both the call as if friend_inline was in global scope (the standard said "global definition") and the call through the :: scope resolution operator such as P :: friend_inline(); Neither worked. I also tried adding a public member to P as a "wrapper" of friend_inline (so making it and its friendship redundant), but the compiler claimed that friend_inline was undeclared in the class scope... I can't understand... Graziano Servizi