Bug 56041 - Constexpr conversion function definition not found in template argument context
Summary: Constexpr conversion function definition not found in template argument context
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: 5.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2013-01-18 22:54 UTC by W E Brown
Modified: 2014-11-20 03:37 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-01-19 00:00:00


Attachments
C++11 metaprogramming experiment (488 bytes, application/octet-stream)
2013-01-18 22:54 UTC, W E Brown
Details

Note You need to log in before you can comment on or make changes to this bug.
Description W E Brown 2013-01-18 22:54:04 UTC
Created attachment 29215 [details]
C++11 metaprogramming experiment

Enclosed code fails to compile, but should.

Tested with:
  g++-mp-4.7 (MacPorts gcc47 4.7.2_2) 4.7.2
  g++-mp-4.8 (MacPorts gcc48 4.8-20130113_0) 4.8.0 20130113 (experimental)

Compiled via:
  g++-mp-4.7 -O3 -std=c++0x main.cc
  g++-mp-4.8 -O3 -std=c++0x main.cc

Use of expression true_type{} as template argument corresponding to bool template parameter produces diagnostic:
  'constexpr integral_constant<T, v>::operator T() const [with T = bool; T v = true]' used before its definition

[The syntax variant true_type() [note parentheses instead of braces as shown above] is correctly diagnosed, applying 14.3/2.  This variant, as well as a C++03-style variant, are present but commented out in the attachment; I left them for possible additional experimentation.]

Using braces should force interpretation as an expression, not a type.  That expression should result in a default-constructed temporary object of the named type; that type, defined earlier in the source, has a conversion operator defined inline.  However, the compiler claims that the operator's definition is not yet defined at the point of (implicit) use.
Comment 1 Jason Merrill 2014-11-20 03:25:59 UTC
Author: jason
Date: Thu Nov 20 03:25:26 2014
New Revision: 217823

URL: https://gcc.gnu.org/viewcvs?rev=217823&root=gcc&view=rev
Log:
	PR c++/56041
	* cp-tree.h (struct processing_template_decl_sentinel): New.
	* pt.c (instantiate_non_dependent_expr_internal): Split out from...
	(instantiate_non_dependent_expr_sfinae): Here.
	(convert_nontype_argument): Use them.
	* constexpr.c (fold_non_dependent_expr): Use them.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-conv1.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/pt.c
Comment 2 Jason Merrill 2014-11-20 03:37:38 UTC
Fixed for GCC 5.