[cfe-dev] Question about is_standard_layout

David Blaikie via cfe-dev cfe-dev at lists.llvm.org
Fri Aug 13 09:18:24 PDT 2021


This class doesn't meet the definition of "standard layout" due to
violating the 6th bullet point:

"Has all non-static data members and bit-fields declared in the same class
(either all in the derived or all in some base)"

"Foo" has one member declared in "Foo" and one member declared in its base
"Base".

On Fri, Aug 13, 2021 at 9:13 AM David Barto via cfe-dev <
cfe-dev at lists.llvm.org> wrote:

> According to
> https://en.cppreference.com/w/cpp/named_req/StandardLayoutType, this
> should report true:
>
> #include <iostream>
> #include <type_traits>
>
> struct Base {
>   int b_a;
> };
>
> struct Foo : Base {
>   int a;
> };
>
> int main()
> {
>   std::cout << std::boolalpha;
>   std::cout << "Base  " << std::is_standard_layout<Base>::value << "\n";
>   std::cout << "Foo   " << std::is_standard_layout<Foo>::value << "\n";
> }
>
> 1103_ clang++ -std=c++14 /tmp/XXX.cpp -o /tmp/XXX
> 1104_ /tmp/XXX
> Base  true
> Foo   false
> 1105_ clang++ --version
> Apple clang version 12.0.5 (clang-1205.0.22.11)
> Target: x86_64-apple-darwin20.5.0
> Thread model: posix
> InstalledDir:
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
>
> Or is this just an Apple/Clang thing and I should complain to them?
>
> David
>
> David Barto | Principal Engineer
> barto at cambridgesemantics.com
>
>
>
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20210813/b17bc9d5/attachment.html>


More information about the cfe-dev mailing list