Skip to content

Fix detection of __datasizeof with Clang. #94174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2024

Conversation

EricWF
Copy link
Member

@EricWF EricWF commented Jun 2, 2024

The __has_extension builtin macro is the same as __has_feature when
-pedantic-errors is specified, which means we don't get the right
information about __datasizeof being available.

Using __has_keyword (really !__is_identifier) will tell the truth
even when -pedantic-errors is specified.

This means we always have __datasizeof under Clang

The `__has_extension` builtin macro is the same as __has_feature when
-pedantic-errors is specified, which means we don't get the right
information about __datasizeof being available.

Using __has_keyword (really !__is_identifier) will tell the truth
even when -pedantic-errors is specified.

This means we always have __datasizeof under Clang
@EricWF EricWF requested a review from a team as a code owner June 2, 2024 21:39
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jun 2, 2024
@llvmbot
Copy link
Member

llvmbot commented Jun 2, 2024

@llvm/pr-subscribers-libcxx

Author: Eric (EricWF)

Changes

The __has_extension builtin macro is the same as __has_feature when
-pedantic-errors is specified, which means we don't get the right
information about __datasizeof being available.

Using __has_keyword (really !__is_identifier) will tell the truth
even when -pedantic-errors is specified.

This means we always have __datasizeof under Clang


Full diff: https://github.com/llvm/llvm-project/pull/94174.diff

1 Files Affected:

  • (modified) libcxx/include/__type_traits/datasizeof.h (+1-1)
diff --git a/libcxx/include/__type_traits/datasizeof.h b/libcxx/include/__type_traits/datasizeof.h
index 54fde242ebcde..35c12921e8ffa 100644
--- a/libcxx/include/__type_traits/datasizeof.h
+++ b/libcxx/include/__type_traits/datasizeof.h
@@ -26,7 +26,7 @@
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
-#if __has_extension(datasizeof)
+#if __has_keyword(__datasizeof) || __has_extension(datasizeof)
 template <class _Tp>
 inline const size_t __datasizeof_v = __datasizeof(_Tp);
 #else

@ldionne
Copy link
Member

ldionne commented Jun 5, 2024

Good find! -pedantic-errors is really a confusing option.

@EricWF EricWF merged commit 1d75c59 into llvm:main Jun 5, 2024
56 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants