This is an archive of the discontinued LLVM Phabricator instance.

Properly ignore mismatched exception specifiers in MSVC Compat mode.
ClosedPublic

Authored by rnk on Sep 14 2019, 5:41 PM.

Details

Summary

This fixes the error compiling _com_ptr_t described in https://bugs.llvm.org/show_bug.cgi?id=42842

In MSVCCompat mode, clang already attempts to downgrade these mismatches to a warning, but because C++17 considers the specifiers part of the type, the check in MergeFunctionDecl needs to ignore these specifiers for purpose of comparison.

Diff Detail

Repository
rL LLVM

Event Timeline

alexfusco created this revision.Sep 14 2019, 5:41 PM
rnk added inline comments.Sep 16 2019, 11:43 AM
lib/Sema/SemaDecl.cpp
3565–3572 ↗(On Diff #220238)

I wonder if we should simplify this to just call hasSameFunctionTypeIgnoringExceptionSpec in all modes. Essentially, just trust that CheckExceptionSpecification did the right thing, in case it returns false for other reasons in the future. It might actually be better for error recovery, for example, to continue adding this overload when exception specifications don't match. I'll try that and see if it passes tests.

Updated to unconditionally ignore the exception spec here, since it has already been compared.

alexfusco marked an inline comment as done.Sep 16 2019, 12:10 PM
rnk commandeered this revision.Sep 16 2019, 12:53 PM
rnk edited reviewers, added: alexfusco; removed: rnk.

Taking this to move the test around and try the other version...

rnk updated this revision to Diff 220376.Sep 16 2019, 12:54 PM
  • move test
alexfusco accepted this revision.Sep 16 2019, 1:02 PM
This revision is now accepted and ready to land.Sep 16 2019, 1:02 PM
alexfusco added inline comments.Sep 16 2019, 1:23 PM
clang/test/SemaCXX/ms-exception-spec.cpp
2 ↗(On Diff #220376)

Dynamic exception specifiers are also an error in C++17, which causes issues on line 4 and 8 in this invocation

14 ↗(On Diff #220376)

There's also a (pre-existing and incorrect) note here that this is also the previous declaration and a note on line 18 that it's in instantiation of that template.

zahen added a subscriber: zahen.Sep 17 2019, 8:02 AM

Is there any interest in supporting the cl.exe flag /permissive-? I considered a hard error on mismatched exception specifier in clang-cl a feature, not a bug. If msvc compat mode respected that flag this could continue to be an error with that flag set (and upgraded strictness in other cases).

thakis added a subscriber: thakis.Sep 17 2019, 8:16 AM

Is there any interest in supporting the cl.exe flag /permissive-? I considered a hard error on mismatched exception specifier in clang-cl a feature, not a bug. If msvc compat mode respected that flag this could continue to be an error with that flag set (and upgraded strictness in other cases).

Does /permissive- in cl.exe turn this specific thing into an error? If not, we don't want to add this under that flag.

You can always use -Werror=microsoft-exception-spec to turn this into an error.

This behavior is necessary to parse system headers, and the general strategy for system headers is "accept enough to be able to parse system headers, but emit a warning". https://docs.google.com/presentation/d/1oxNHaVjA9Gn_rTzX6HIpJHP7nXRua_0URXxxJ3oYRq0/edit#slide=id.p has some more words on this (slides 26/27).

zahen added a comment.EditedSep 17 2019, 8:36 AM

I just checked a trivial mismatch example in clang 8.0 (https://godbolt.org/z/wiSAp6) and I missed how the compatibility mode operates. I withdraw my suggestion since the patch keeps consistency with the existing behavior. Thanks for the -Werror=microsoft-exception-spec suggestion that's exactly what our project wants.

rnk updated this revision to Diff 220564.Sep 17 2019, 1:23 PM
  • simplify merging check
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptSep 17 2019, 1:27 PM