Shafik Yaghmour · @shafik
354 followers · 287 posts · Server hachyderm.io

#239 Given the following in C++:

constexpr const char *x = "Hello World";
constexpr const char *y = "Hello World";
constexpr bool b = x == y;

Without checking, is this well-formed?

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
332 followers · 255 posts · Server hachyderm.io

#237 Given the following in C++:

struct A{};
using T = auto() -> auto(*)() -> auto(*)() -> A;

Without checking, is this well-formed?

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
320 followers · 250 posts · Server hachyderm.io

#236 Given the following in C++:

struct A {int a;};
struct B : public A {int x;};

void f() {
B b{{},.x=1}; // Aggregate init base
// and designted init x
// Well-formed?
}

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
308 followers · 227 posts · Server hachyderm.io

#235 Given the following in C++:

struct A {void f();};
struct B {void f(int);};
struct C : A, B {};

void g() {
C c;
c.f(); // Ambiguous?
}

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
306 followers · 210 posts · Server hachyderm.io

#234 Given the following in C++:

struct A {int a;};

struct B : public A {int x;};

void f() {
B b{.a=1,.x=1}; // Well-formed?
}

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
294 followers · 202 posts · Server hachyderm.io

#233 Given the following in C++:

struct A {} ;

void f() {
new struct A{}; // Well-formed?
}

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
283 followers · 198 posts · Server hachyderm.io

#232 Given the following in C++:

template <typename T>
concept C [[deprecated]]= true; // Can we deprecate a concept?

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
279 followers · 195 posts · Server hachyderm.io

#231 Given the following in C++:

struct S {
union {
union { // Nested anon union, valid?
int x = 1;
float f;
};
void *p ;
};
};

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
274 followers · 186 posts · Server hachyderm.io

#230 Given the following in C++:

struct X {int a, b;};
struct Y {int c; double d;};
union U {X x; Y y;};

constexpr int f(){
U u = {{1,2}};
return u.y.c; // Common initial sequence,ok?
}

constexpr int x=f();

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
272 followers · 172 posts · Server hachyderm.io

#229 Given the following in C++:

void f() {
union {
int x=1;
float y;
};

[x]() {}; // Allowed to capture x?
}

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
246 followers · 132 posts · Server hachyderm.io

I have two good options for next weeks quiz.

Neither one will make most folks happy.


#cpppolls #cplusplus

Last updated 1 year ago

Shafik Yaghmour · @shafik
244 followers · 114 posts · Server hachyderm.io

#226 Given the following in C and C++

struct A {
int y : (int)(double)10.f;
};

Without checking, valid code?

C | C++
=========
A. No | No
B. No| Yes
C. Yes | No
D. Yes | Yes



#cplusplus #cpppolls #programming

Last updated 1 year ago

Shafik Yaghmour · @shafik
235 followers · 95 posts · Server hachyderm.io

#225 Given the following in C++:

int x{3};
int y{x};

template <typename T>
static const int z{y};

int main() {
return z<void>; // What is the value returned?
}

Without checking:

A. 3
B. 0
C. Something else
D. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
224 followers · 68 posts · Server hachyderm.io

#224 Given the following in C++:

union U {
int x;
float y;
};

void f() {
U u{.x=2,.y=1}; // Well-formed? Initialize x and then override and initialize y?
}

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
216 followers · 52 posts · Server hachyderm.io

#223 Given the following in C++:

class A{};

using B = A;

void f() {
class B a2; // Well-formed?
}

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
210 followers · 47 posts · Server hachyderm.io

#222 Given the following in C++:

struct A {
bool operator[](int);
};

void f() {
A a;
int arr[2]{};

1[arr]; // Same as arr[1]
1[a]; // Same as a[1]??
}

Without checking:

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
199 followers · 44 posts · Server hachyderm.io

#221 Given the following in C++:

void f() {
float f = 1f; // Well-formed?
}

A. Yes
B. No
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
194 followers · 41 posts · Server hachyderm.io

#220 Given the following in C++:

void f() {
auto h = [y=0]<typename y>(y) // Does the 2nd y shadow or ill-formed?
{ return 0; };
}

A. Shadow
B. Ill-formed
C. Show results


#cplusplus #cpppolls

Last updated 1 year ago

Shafik Yaghmour · @shafik
186 followers · 32 posts · Server hachyderm.io

#219 Given the following in C++:

<type_traits>

template <typename T>
void f(std::add_rvalue_reference_t<T>){}

Without checking, is this well-formed?

A. Yes
B. No
C. Show results


#include #cplusplus #cpppolls

Last updated 1 year ago

Bart Janssens 🇧🇪 · @bart
663 followers · 884 posts · Server sociabl.be

@shafik So great to see the on Mastodon now. How I missed the bitter taste of failure 🙃

#cpppolls

Last updated 1 year ago