text: Why is it possible to declare a C++ Array (on stack) with a size, that isn't const or constexpr?
  Almost all sources on the internet say that an array needs to be declared with a value, that is known at compile time like constexpr variables. But this code works fine for me:
  int main(){ int a; std::cin >> a; int arr[a]; //... }
  normally you'd exspect an compiler error, would't you? So I'm confused why this works (compiled with "g++ -m32 -g -std=c++20 main.cpp -o main" on linux)
  See also questions close to this topic
  - Floating point exception: 8 when constructing object C++
  I am getting the error Floating point exception: 8 at runtime when trying to run my code. I am making a decision learning tree, and am at the point of the error just trying to create a node.
  My class declaration looks like this:
  #ifndef NODE_H #define NODE_H class Node{ public: int label; Node* left; Node* right; int attr; double splitval; Node(); ~Node(); }; #endif //NODE_H
  and the constructor and destructor implementations look like this:
  #include <iostream> #include "Node.h" using namespace std; Node::Node(){ label = 0; left = NULL; right = NULL; attr = -1; splitval = -1; } Node::~Node(){}
  I know that the constructor runs, as I can add in a cout to the end of it (after splitval = -1;) and that will show up when I run the code.
  My section in main looks like this:
  Node* nIf = new Node(); cout << "made nIf node" << endl;
  The cout in main does not print to my command line, so the error must be happening at the very end of the object construction, but I don't understand what I can do to fix it.
  - How to print incorrect pas or username?
  StreamReader sr = new StreamReader(dosyaAdresi); string r = sr.ReadToEnd(); sr.Close(); string[] txt = r.Split(','); for(int i=0; i < txt.Length; i++) { if (txtkullaniciAdi.Text == txt[i] && txtPass.Text == txt[i + 1]) { MessageBox.Show("correct"); break; } i++; }
  How to make a messagebox for error after verifying the username and passwords that I read from the text file
  -?
  - lambda capture error with gcc, compiles with clang
  The following program does not compile with g++ 10.1.0
  #include <iostream> template <unsigned int N> struct A { constexpr static unsigned int i = N; }; template <class U> void f() { constexpr unsigned int i = U::i; auto lambda = [&]() { if constexpr (i > 2) { std::cout << "i > 2" << std::endl; } else { std::cout << "i <= 2" << std::endl; } }; lambda(); } int main() { f<A<1>>(); f<A<3>>(); return 0; }
  With
  g++ -Wall -std=c++17 -O3 -pedantic -o test test.cpp
  the error is:
  test.cpp: In lambda function: test.cpp:13:24: error: lambda capture of ‘i’ is not a constant expression 13 | if constexpr (i > 2) {
  However, the same code compiles fine with clang++ 11.1.0 and produces the expected result.
  Which compiler is correct?
  - Are there any pitfalls converting compile-time constant members from enum to static constexpr?
  Consider the following two pieces of code:
  template <int X> struct Foo { enum { x = X }; };
  vs
  template <int X> struct Foo { static constexpr int x = X; };
  (The former is a frequent pattern in a library I want to modernize to C++17.)
  I have looked through many questions/answers on here covering the differences between the
  enumvs
  static constexprvariants, but with C++17 having changed the behavior of
  static constexpr(by making such variables implicitly inline) many of them are outdated (example). It's not perfectly clear to me what the remaining differences are and if I am missing something important.
  Is going from the first snippet above to the second a safe transformation? Or are there any potential breakages or changes in behavior affecting user code that I should be aware of?
  - Templated constexpr variable
  I want to confirm that this code is legal (or not legal?) C++17.
  #include <iostream> template<int N> inline constexpr float MyConst; template<> inline constexpr float MyConst<1> = 1.1f; template<> inline constexpr float MyConst<2> = 2.2f; int main () { std::cout << MyConst<1> << '\n'; return 0; }
  I don't get errors (and get correct output) if compiled by g++ and MSVC,
  but Intel and clang give an error:
  test.cpp(3): error: missing initializer for constexpr variable template<int N> inline constexpr float MyConst; ^
  Compiled with
  -std=c++17(
  /std:c++17for MSVC).
  Tried with latest compilers on godbolt as well as on my local machine.