Questions tagged [elision]

The removal by a compiler of statements or operations appearing in the input program or implicit in its general interpretation, which it determines to be without discernable effect.

13 questions
120
votes
1 answer

Do I need to use the "import type" feature of TypeScript 3.8 if all of my imports are from my own file?

I have a simple file types.ts that defines some types: export interface MyInterface { // ... } export const enum MyEnum { // ... } export type MyType = { // ... } I have read about the new feature import type for the latest typescript…
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
7
votes
3 answers

Is this "elision failure" language-mandated?

Consider the following code: #include #include int bar() { std::pair p { 123, "Hey... no small-string optimization for me please!" }; return p.first; } (simplified thanks to @Jarod42 :-) ...)…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
4
votes
1 answer

How does the 'explicit' keyword affect C++ copy constructors and function parameters?

The "explicit" keyword to modify the copy constructor can cause problems. Objects passed as function parameters are particularly susceptible to these issues. here are my codes: #include #include class Pig{ public: …
Andrés
  • 41
  • 2
4
votes
1 answer

Is eliminating construction of unused object allowed in standard even if constructor has observable side-effects?

Consider the following code: #include struct M { M() { std::cout << "M\n"; } }; template struct Test { Test() { std::cout << "Test\n"; } inline static auto m = M{}; }; int main() { Test t1; //Test t; …
αλεχολυτ
  • 4,792
  • 1
  • 35
  • 71
4
votes
2 answers

Can I tell my compiler to ignore the side effects of a statement or a function?

Suppose my code has the following function: inline int foo() { bar(); int y = baz(); return y; } and suppose that bar() and baz() have side-effects. If I write: int z = foo(); printf("z is %d\n", z); then obviously both bar() and baz()…
einpoklum
  • 118,144
  • 57
  • 340
  • 684
2
votes
0 answers

C++14 new elision and new combining (a.k.a. allocator or allocation elision or combining) - what are the use cases?

What are the use cases for new elision and new combining, added in C++14? (As per cppreference on new)? And also: Does limiting them to "replacable allocation functions" mean they only apply if operator new has been replaced? Or does it also…
davidbak
  • 5,775
  • 3
  • 34
  • 50
1
vote
1 answer

Why destructor is called if the return operation is elided?

I have the following code that mimics an elision testcase class Obj { public: int x = 0; Obj(int y) : x(y) {std::cout << "C\n"; } ~Obj() { std::cout << "D\n"; } }; auto factory() { std::vector vec {1,2,3}; std::cout<< &vec[0] <<…
Matteo Galeotti
  • 105
  • 1
  • 9
1
vote
1 answer

Why do relaxed atomic operations prevent compiler optimizations?

C++ compilers are allowed to elide or combine allocations. However, it seems that if allocated memory is accessed with atomic operations (even with relaxed memory order) that allocation cannot be elided by GCC and Clang. // new/delete are…
Altan
  • 103
  • 1
  • 7
1
vote
1 answer

move semantics in constructor in return statement

I know that when returning a local in order to keep RVO we should allow the compiler to perform move elision by returning a value like so std::vector some_func(){ std::vector my_vector; //do something return…
user3353819
  • 911
  • 2
  • 8
  • 21
1
vote
0 answers

How do I check if hardware lock elision (HLE) is disabled in libpthread.so.0?

From this post, I learned that HLE can be enabled/disabled differently depending on the glibc version. How do I check whether HLE is enabled in the libpthread library object for glibc prior to and after version 2.27? I was thinking to use dlsym(void…
Simon
  • 51
  • 3
0
votes
1 answer

How can I verify that the compiler is eliding my coroutine heap allocations?

I'm having trouble understanding the memory allocations made by C++20 coroutines. For my code, I would like to verify that the compiler is eliding heap allocations, and if it isn't, to find out what data is being placed within that allocation. My…
0
votes
0 answers

Index of elisions in JavaScript arrays

What is the difference between the undefined elements in JavaScript arrays: created directly, created with elision? Elements of case 1. and 2. both have undefined types and values, but the ones born in elision don't have indexes (or any enumerable…
theDavidBarton
  • 7,643
  • 4
  • 24
  • 51
-1
votes
1 answer

Meaning of this= in GDB

I understand the general concept of using optimization flags like -O2 and ending up having had things optimized out, makes sense. But what does it mean for the 'this' function parameter in a gdb frame to be optimized out? Does it mean the use of an…
JoeManiaci
  • 435
  • 3
  • 15