This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/66287] New: [C++11] A constexpr variable of "const int* const&" cannot be initialized


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

            Bug ID: 66287
           Summary: [C++11] A constexpr variable of "const int* const&"
                    cannot be initialized
           Product: gcc
           Version: 6.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: kariya_mitsuru at hotmail dot com
  Target Milestone: ---

Created attachment 35627
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35627&action=edit
g++ -v

Please see the sample code below.

=========== sample code ===========
constexpr const int& i = 42;
constexpr const int* const& p = &i;

int main() {}
=========== sample code ===========
================================== output ==================================
prog.cc:2:34: error: modification of '_ZGR1p1' is not a constant-expression
 constexpr const int* const& p = &i;
                                  ^
================================== output ==================================
cf. http://melpon.org/wandbox/permlink/RfoewySFecAtfEOV

I think that "&i" is a valid constant expression.


Note that it is compiled successfully if the variable "i" is not a reference.

=========== sample code ===========
constexpr const int i = 42;
constexpr const int* const& p = &i;

int main() {}
=========== sample code ===========
cf. http://melpon.org/wandbox/permlink/qdLd3nqzteNRrnow


Note also that an rvalue reference causes the same error.

=========== sample code ===========
constexpr int&& i = 42;
constexpr int*&& p = &i;

int main() {}
=========== sample code ===========
================================== output ==================================
prog.cc:2:23: error: modification of '_ZGR1p1' is not a constant-expression
 constexpr int*&& p = &i;
                       ^
================================== output ==================================
cf. http://melpon.org/wandbox/permlink/TzS1T2dzyjSMxlKd


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]