Bug 63283 - constexpr function called by templated function is not treated as constexpr
Summary: constexpr function called by templated function is not treated as constexpr
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.1
: P3 normal
Target Milestone: 5.0
Assignee: Jason Merrill
URL:
Keywords: rejects-valid
Depends on:
Blocks: constexpr
  Show dependency treegraph
 
Reported: 2014-09-17 02:56 UTC by roc@ocallahan.org
Modified: 2015-01-15 22:07 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.2, 4.9.1, 5.0
Last reconfirmed: 2014-09-17 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description roc@ocallahan.org 2014-09-17 02:56:30 UTC
[roc@eternity tmp]$ cat test.cc
#include <stdio.h>
constexpr int array_length(int (&array)[3]) { return 3; }
int a[] = { 1, 2, 3 };
template <typename T> int f() {
  struct { int e[array_length(a)]; } t;
  return sizeof(t);
}
int main() { printf("%d\n", f<void>()); }

[roc@eternity tmp]$ g++ -std=c++11 -o ~/tmp/test ~/tmp/test.cc && ~/tmp/test
/home/roc/tmp/test.cc: In function ‘int f()’:
/home/roc/tmp/test.cc:5:33: error: array bound is not an integer constant before ‘]’ token
   struct { int e[array_length(a)]; } t;
                                 ^
[roc@eternity tmp]$ g++ -v
Using built-in specs.
COLLECT_GCC=/usr/bin/g++
COLLECT_LTO_WRAPPER=/usr/libexec/gcc/x86_64-redhat-linux/4.8.3/lto-wrapper
Target: x86_64-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla --enable-bootstrap --enable-shared --enable-threads=posix --enable-checking=release --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-gnu-unique-object --enable-linker-build-id --with-linker-hash-style=gnu --enable-languages=c,c++,objc,obj-c++,java,fortran,ada,go,lto --enable-plugin --enable-initfini-array --enable-java-awt=gtk --disable-dssi --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre --enable-libgcj-multifile --enable-java-maintainer-mode --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib --with-isl=/builddir/build/BUILD/gcc-4.8.3-20140624/obj-x86_64-redhat-linux/isl-install --with-cloog=/builddir/build/BUILD/gcc-4.8.3-20140624/obj-x86_64-redhat-linux/cloog-install --with-tune=generic --with-arch_32=i686 --build=x86_64-redhat-linux
Thread model: posix
gcc version 4.8.3 20140624 (Red Hat 4.8.3-1) (GCC) 

My friend also sees this in g++ 4.9.1.

clang++ 3.4 compiles the code successfully. Removing "template <typename T>" from f() (and changing main() to match) makes the problem go away.
Comment 1 Jason Merrill 2015-01-15 20:46:36 UTC
Author: jason
Date: Thu Jan 15 20:46:03 2015
New Revision: 219686

URL: https://gcc.gnu.org/viewcvs?rev=219686&root=gcc&view=rev
Log:
	PR c++/63283
	* constexpr.c (potential_constant_expression_1): Handle reference
	args in templates.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/constexpr-template8.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/constexpr.c
    trunk/gcc/testsuite/g++.dg/cpp0x/static_assert10.C
Comment 2 Jason Merrill 2015-01-15 21:46:21 UTC
Fixed for GCC 5.
Comment 3 roc@ocallahan.org 2015-01-15 22:07:13 UTC
Thanks!!!