Open diggit opened 4 years ago
Here is minimal example code, without those template tricks. Line numbers does not match, otherwise same behavior.
template<typename Derived>
struct Base {
bool operator<(Derived const& rhs) const {
static_assert(true, "Your type must add this requirement.");
auto& me = static_cast<const Derived&>(*this);
return me.value < rhs.value;
}
bool operator<=(Derived const& rhs) const {
static_assert(false, "Your type must add this requirement.");
auto& me = static_cast<const Derived&>(*this);
return me.value <= rhs.value;
}
bool operator==(Derived const& rhs) const {
static_assert(true , "Your type must add this requirement.");
auto& me = static_cast<const Derived&>(*this);
return me.value == rhs.value;
}
};
struct Child : Base<Child> {
friend Base;
protected:
int value;
};
int main(void) {
Child a, b;
a < b; //vscode does no complain (OK), compiles (OK)
a <= b; //vscode does no complain (wrong), compilation fails due to static_assert on line 52 (OK)
a == b; //vscode complains about multiple == operators, compler does not, compiles (OK)
a != b; //vscode complains about multiple != operators (wrong), non of them exist and compilations fails (OK)
return 0;
}
Relevant lines from cmake:
add_compile_options(-Wall -pedantic -Og -g)
add_compile_options($<$<COMPILE_LANGUAGE:CXX>:-Weffc++>)
set_target_properties(${PROJECT_NAME} PROPERTIES CXX_STANDARD 20)
Thanks for reporting this. The issues comes from code in VS, so I've filed a bug at https://developercommunity.visualstudio.com/content/problem/959748/cc-intellisense-static-assert-ignored-in-sfinae-an.html .
Type: LanguageService
Describe the bug
Steps to reproduce
c_cpp_propertis.json
for quick access cpp file in gist also attached in zip
Verify, that template works as expected
static_list flags
inDerived
class tellsBase
class which asserts deactivate and thus enable some operatorsa <= b;
static_assert
as expectedOperatorRequirements::LEQ
to list in line 65, this enables operator<=
by deactivating static_assertvscode behavior
flags.cpp
into original statea < b;
vscode does no complain (OK), compiles (OK) b)a <= b;
vscode does no complain (wrong, operator does not exist due to static_assert), compilation fails due to static_assert on line 52 (OK) c)a == b
vscode complains:Compiles fine
d)
a!=b
vscode complains:Compilation fails (g++ error):
Expected behavior
<=
operator when disabled by static assert==
operator when there is only one implementation!=
operator missingLogs
c_cpp_server_log just commented lines to state when source compiles, nothing interesting there ``` cpptools/getCodeActions: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp (id: 451) cpptools/activeDocumentChange: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp cpptools/textEditorSelectionChange cpptools/textEditorSelectionChange idle loop: reparsing the active document Checking for syntax errors: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp Queueing IntelliSense update for files in translation unit of: /home/diggit/dev/flagtest/soclim/src/flagtest.cpp cpptools/cpptools_finishUpdateSquiggles Error squiggle count: 1 Update IntelliSense time (sec): 0.259 Database safe to open tag parsing file: /home/diggit/dev/flagtest/soclim/src/flagtest.cpp cpptools/getDocumentSymbols: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp (id: 452) cpptools/getDocumentSymbols Database safe to open cpptools/activeDocumentChange: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp cpptools/textEditorSelectionChange cpptools/textEditorSelectionChange cpptools/getCodeActions: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp (id: 453) idle loop: reparsing the active document Checking for syntax errors: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp Queueing IntelliSense update for files in translation unit of: /home/diggit/dev/flagtest/soclim/src/flagtest.cpp textDocument/hover: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp (id: 454) cpptools/cpptools_finishUpdateSquiggles Error squiggle count: 1 Update IntelliSense time (sec): 0.264 cpptools/getCodeActions: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp (id: 455) textDocument/hover: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp (id: 456) textDocument/hover: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp (id: 457) cpptools/getCodeActions: file:///home/diggit/dev/flagtest/soclim/src/flagtest.cpp (id: 458) ```Screenshots