« first day (2340 days earlier)      last day (729 days later) » 

11:49
Hi. I was wondering whether a C++ compiler should (is allowed to) consider unreachable code in automatic type deduction.
   [[nodiscard]] auto operator <=>(ByPhone const& other) const
   {
       int const my_phone = std::stoi(this->person.Phone);
       int const other_phone = std::stoi(other.person.Phone);
       return my_phone <=> other_phone;  // I inserted this, because I think it's equivalent to the next 3 lines; deduces to std::strong_ordering
      if (my_phone < other_phone) return -1;  // unreachable code returning int
      if (my_phone > other_phone) return 1;
      return 0;
   }
Compiler error (MSVC) C3487: all return expressions must deduce to the same type
I will certainly remove the dead code once I verified the code still works.
I can also workaround easily by commenting out the code.
I'm just curious whether this is good compiler behavior.
nwp
nwp
I don't think it's allowed, but you'd need to dig through the standard to make sure. I vaguely remember they went with just all the returns without analysis to avoid the halting problem.
You can sometimes do this on purpose with if constexpr.
Hmm, ok, the halting problem. Yes, basically it boils down to that. It's just so obvious here, but maybe not trivial to decide in general.
12:29
@nwp it's not a template so AFAIK it's required to still parse unreachable code
 
8 hours later…
20:40
If I'm using g++ as my compiler in VSCode, why might I be seeing clang warnings when I run make?
I have a c_cpp_settings.json in a .vscode directory in my project that seems to reference a compiler path to /usr/bin/clang, but if I change that to g++, nothing changes. I'm not really sure if this JSON plays a role in this issue
nwp
nwp
Maybe that is not the thing it starts when you press F5.
What do you mean? Pressing F5 just shows a bunch of errors for me because the compile invocation is missing important things
this is what I see ^
nwp
nwp
20:56
Ah
VSC uses a plugin to give you auto-complete and underline things that are fishy. It uses clangd for that.
Interestingly, the clang warnings only seem to appear when I have a -M flag in my CXXFLAGS
@nwp Is there a way to disable this behavior?
nwp
nwp
You can disable or uninstall the plugin.
I would recommend against it. You'll probably lose auto-complete and maybe even semantic highlighting.
The plugin has settings. It's probably under clang-tidy, but not sure.
It's probably best to add flags for things you don't want to see. For -Wsomething-something add -Wno-something-something to turn that specific warning of.
21:15
Add that where though? My confusion is that I'm not explicitly using clang at any point, so I don't know where VSC is pulling it from, so I don't know how to change the apparent VSC invocation

« first day (2340 days earlier)      last day (729 days later) »