public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Casey at Carter dot net" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66184] New: Rejection of partial specialization of a variable template in a non-global namespace
Date: Sun, 17 May 2015 17:53:00 -0000	[thread overview]
Message-ID: <bug-66184-4@http.gcc.gnu.org/bugzilla/> (raw)

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66184

            Bug ID: 66184
           Summary: Rejection of partial specialization of a variable
                    template in a non-global namespace
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Casey at Carter dot net
  Target Milestone: ---

Created attachment 35558
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35558&action=edit
testcase.cpp

Both 5.1.0 on Wandbox and 6.0 r223061 reject this program:

namespace foo {
template <class, class> constexpr bool same = false;
template <> constexpr bool same<void,void> = true;
template <class T> constexpr bool same<T,T> = true;

static_assert(same<int*,int*>, "");
static_assert(!same<int,int*>, "");
}

int main() {}

with error message:

bug2.cpp:4:35: error: specialization of ‘template<class, class> constexpr const
bool foo::same< <template-parameter-1-1>, <template-parameter-1-2> >’ in
different namespace [-fpermissive]
 template <class T> constexpr bool same<T,T> = true;
                                   ^
bug2.cpp:2:40: error:   from definition of ‘template<class, class> constexpr
const bool foo::same< <template-parameter-1-1>, <template-parameter-1-2> >’
[-fpermissive]
 template <class, class> constexpr bool same = false;
                                        ^
The full specialization of same<void,void> is accepted regardless of namespace.
Both versions compile the program correctly if "same" is in the global
namespace.
>From gcc-bugs-return-486482-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Sun May 17 18:20:48 2015
Return-Path: <gcc-bugs-return-486482-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 125682 invoked by alias); 17 May 2015 18:20:48 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 125628 invoked by uid 48); 17 May 2015 18:20:44 -0000
From: "harald at gigawatt dot nl" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/65942] [5/6 Regression] [C++14] cannot use std::function as comparator in algorithms
Date: Sun, 17 May 2015 18:20:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Version: 5.0
X-Bugzilla-Keywords: rejects-valid
X-Bugzilla-Severity: normal
X-Bugzilla-Who: harald at gigawatt dot nl
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Resolution:
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: redi at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-65942-4-mLiQeon8Z4@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-65942-4@http.gcc.gnu.org/bugzilla/>
References: <bug-65942-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-05/txt/msg01322.txt.bz2
Content-length: 1918

https://gcc.gnu.org/bugzilla/show_bug.cgi?ide942

Harald van Dijk <harald at gigawatt dot nl> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |harald at gigawatt dot nl

--- Comment #11 from Harald van Dijk <harald at gigawatt dot nl> ---
GCC and clang are instantiating constexpr function bodies when only the
signature should be checked (when they appear in unevaluated expressions). A
shorter example program:

template <typename T> constexpr int f(T t) { return t; }
int main() { sizeof(f("")); }

This is rejected by GCC and clang, but accepted by Intel and Sun C++. As far as
I can tell, it should be accepted. f is used in a context where a definition of
f is not required, so f should not be instantiated. f is used in a way that
involves overload resolution, so a declaration of f is instantiated, but that
declaration does not contain the error that GCC and clang report.

GCC and clang accept it when constexpr is removed.

It's made worse by the fact that it happens even in SFINAE contexts, where such
an error should at worst lead to a substitution failure:

template <typename T> constexpr int f(T t) { return t; }
template <typename T, typename = decltype(f(T()))> void g(T) { }
void g(...) { }
int main() { g(""); }

Here, either the use of f(T()) is an error, so overload resolution should
discard the first g overload, and the program should be accepted, or the use of
f(T()) is valid, so overload resolution should prefer the first g overload, and
the program should still be accepted. But even this is rejected by GCC and
clang.

Even if this gets worked around in libstdc++, it's probably worth tracking this
as a C++ frontend bug as well.

The programs in my comment here are accepted by G++ 4.5.4 (with -std=c++0x),
and rejected by 4.6.4 and later.


             reply	other threads:[~2015-05-17 17:53 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-17 17:53 Casey at Carter dot net [this message]
2015-05-29 10:12 ` [Bug c++/66184] [C++14] " Casey at Carter dot net
2015-05-29 10:17 ` Casey at Carter dot net

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-66184-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).