[Bug c++/81474] New: out of memory on constexpr calculation

2017-07-18 Thread bobk-off at yandex dot ru
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81474

Bug ID: 81474
   Summary: out of memory on constexpr calculation
   Product: gcc
   Version: 6.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bobk-off at yandex dot ru
  Target Milestone: ---

Code below cause "cc1plus.exe: out of memory allocating 65536 bytes" error on
gcc 6.3.0 for ARM (32bit version). During compilation memory usage grows to
2GB, after it compilation fails. Argument of foo (1) had been picked to
demonstrate bug on simple example. With large types (not trivial types) "out of
memory" error occurs on lower for-cycle depth. Look like the compiler use
"allocation from stack" memory model on each cycle iteration and doesn't free
memory after cycle.

constexpr int foo(size_t c)
{
int a = 0;
for (int i = 0; i < ci++)
{
a += i;
a -= i;
}
return a;
}

constexpr int x = foo(1);

[Bug c++/81781] New: consexpr pointer comparsion error

2017-08-09 Thread bobk-off at yandex dot ru
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81781

Bug ID: 81781
   Summary: consexpr pointer comparsion error
   Product: gcc
   Version: 7.1.1
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bobk-off at yandex dot ru
  Target Milestone: ---

Any gcc version cannot compile code below with error: '((&
std::integral_constant::value) == (& std::integral_constant::value))' is not a constant expression. Compilation success only if
template arguments of left side and right side parts of equation are equal.

static constexpr bool x = &std::integral_constant::value ==
&std::integral_constant::value;

[Bug c++/81474] out of memory on constexpr calculation

2017-09-12 Thread bobk-off at yandex dot ru
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81474

--- Comment #2 from Fedor Bobkov  ---
Thread-starting example is intended only for demonstration of out of memory
error on simply example. In real projects out of memory error occurs with much
smaller loops which just use bigger amount of data.

I had got this error on compile-time bilinear downscaling of signed distance
field image. May be it is not proper way to use constexprs but it is very
useful in embedded applications (with small RAM and big ROM (flash) memory).

[Bug c++/81474] out of memory on constexpr calculation

2017-09-12 Thread bobk-off at yandex dot ru
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81474

--- Comment #4 from Fedor Bobkov  ---
> Can you please elaborate it more? We're interested in a test-case for that ;)

I'll try to make simplified code of this app as soon as possible.

[Bug c++/78609] New: invalid member's visibility detection in constexpr

2016-11-30 Thread bobk-off at yandex dot ru
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78609

Bug ID: 78609
   Summary: invalid member's visibility detection in constexpr
   Product: gcc
   Version: 6.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bobk-off at yandex dot ru
  Target Milestone: ---

All known for me version of gcc failed to compile following code with error "
error: 'char A::data [28]' is private". clang compiles ok. Looks like compiler
incorrectly interprets members visibility.

#include 

struct A
{
private:
char data[28];
public:
constexpr const char * c_str() const { return data; }

template constexpr A(char const (&str)[N]) : data()
{
for (size_t i=0;i
struct B
{
static const constexpr A name = A("Some text");
static const constexpr char * value = name.c_str();
};

template
const constexpr A B::name;

int main()
{
  volatile char d;
  const char * c = B<0>::value;
  while (*c!=0) d = *c++;  
}

[Bug c++/78609] invalid member's visibility detection in constexpr

2016-11-30 Thread bobk-off at yandex dot ru
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78609

--- Comment #1 from Fedor Bobkov  ---
To walk around this bug just change visibility of "data" member to public.

[Bug c++/77598] New: consexpr compilation failure on reference type casting

2016-09-15 Thread bobk-off at yandex dot ru
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=77598

Bug ID: 77598
   Summary: consexpr compilation failure on reference type casting
   Product: gcc
   Version: 4.8.2
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bobk-off at yandex dot ru
  Target Milestone: ---

Compiler fails on type casting of reference during constexpr processing. This
bug is actual for GCC-ARM 4.8.2+ compilers, and GCC-X86-64 5.3+ compilers
(tested on gcc.godbolt.org). clang of any version which supports C++14 compile
code below successfully.

Known walkaround: change type of dtarr variable to "DataTypeBasicX_t &"

#include 
#include 

template
struct DefaultInstanceOf { static constexpr T value = T(); };

template
constexpr T DefaultInstanceOf::value;

enum class BasicDataTypeId_t : uint16_t
{
None = 0,
INTEGER16 = 0x0003,
};


struct DataTypeX_t
{
private:
uint32_t mBitSize;
public:
constexpr uint32_t BitSize() const { return mBitSize; }
constexpr DataTypeX_t(const uint32_t & bitSize) : mBitSize(bitSize) {};
};



struct DataTypeBasicX_t : public DataTypeX_t
{
constexpr DataTypeBasicX_t() : DataTypeX_t(50) {};
};


struct DataTypeBasicArrayX_t : public DataTypeBasicX_t
{
};

struct BaseDataTypes
{
static constexpr const auto & ARRAY_OF_INT =
DefaultInstanceOf::value;
};

constexpr const DataTypeX_t & dtarr10 = BaseDataTypes::ARRAY_OF_INT;
constexpr const size_t bitsz10 = dtarr10.BitSize();

int main()
{
  while (1);
}

Error message:
46 : in constexpr expansion of '(& dtarr10)->DataTypeX_t::BitSize()'
46 : error: accessing value of
'DefaultInstanceOf::value' through a 'const DataTypeX_t'
glvalue in a constant expression
constexpr const size_t bitsz10 = dtarr10.BitSize();
^
Compilation failed

Link to gcc.godbolt.org code: https://godbolt.org/g/lR0dE4

[Bug c++/113809] New: Error of constexpr variable creation due to combined use of std::tuple, copy constructor and static function

2024-02-07 Thread bobk-off at yandex dot ru via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113809

Bug ID: 113809
   Summary: Error of constexpr variable creation due to combined
use of std::tuple, copy constructor and static
function
   Product: gcc
   Version: 13.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bobk-off at yandex dot ru
  Target Milestone: ---

Compiler reports following error on code below:

in 'constexpr' expansion of 'A(MakeFullPGNsMap::value)'
in 'constexpr' expansion of
'((A*)this)->A::A<0>(other.A::mTuple,
(std::make_index_sequence<1>(), std::make_index_sequence<1>()))'
error: the value of 'MakeFullPGNsMap::value' is not usable in a constant
expression


Note: code is strognly reduced to only demonstrate compilation error.

Code: 

#include 
#include 

template
struct ConstantObject { static constexpr T value = { TARGS::value... }; };

template
struct A {

A & operator =(const A & other) = delete;

constexpr A(const std::tuple & tuple) : A(tuple,
std::make_index_sequence()) {}
constexpr A(const A & other) : A(other.mTuple,
std::make_index_sequence()) {}

private:
template
constexpr A(const std::tuple & tuple,
std::index_sequence) : mTuple(tuple), mMap{ &std::get(mTuple)... }
{}

std::tuple mTuple;
const void * mMap[sizeof...(Ts)] = {};
};

template
static constexpr A make_a(const std::tuple & spns) {
return A(spns);
}

struct MakeFullPGNsMap {;
static constexpr A value = make_a(std::make_tuple(5));
};

using X = ConstantObject;

const void * y;

int main() {
y = &X::value;
return 0;
}