-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Closed
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!
Description
Describe the bug
string_view doesn't enforce "non-array trivial standard-layout", related to LWG-3034.
Command-line test case
C:\Temp>type main.cpp
#include <type_traits>
#include <string_view>
template <class charT>
struct test_traits
{
typedef charT char_type;
};
struct NotTrivial {
NotTrivial() : value(3) {}
int value;
};
struct NotStandardLayout {
public:
NotStandardLayout() : one(1), two(2) {}
int sum() const { return one + two; } // silences "unused field 'two' warning"
int one;
private:
int two;
};
int main()
{
{
// array
typedef char C[3];
static_assert(std::is_array<C>::value, "");
std::basic_string_view<C, test_traits<C> > sv;
// expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must not be an array"}}
}
{
// not trivial
static_assert(!std::is_trivial<NotTrivial>::value, "");
std::basic_string_view<NotTrivial, test_traits<NotTrivial> > sv;
// expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be trivial"}}
}
{
// not standard layout
static_assert(!std::is_standard_layout<NotStandardLayout>::value, "");
std::basic_string_view<NotStandardLayout, test_traits<NotStandardLayout> > sv;
// expected-error-re@string_view:* {{static_assert failed{{.*}} "Character type of basic_string_view must be standard-layout"}}
}
}
C:\Temp>cl /W4 /WX /EHsc /std:c++latest main.cpp
Оптимизирующий компилятор Microsoft (R) C/C++ версии 19.28.29213 для x64
(C) Корпорация Майкрософт (Microsoft Corporation). Все права защищены.
/std:c++latest предоставляется как предварительная версия языковых функций из последнего
рабочего черновика C++. Мы приветствуем сообщения об ошибках и предложения к улучшению.
Однако обратите внимание, что эти функции предоставляются как есть, без поддержки и могут
измениться или быть удалены по мере развития рабочего черновика. Дополнительные сведения:
https://go.microsoft.com/fwlink/?linkid=2045807.
main.cpp
Microsoft (R) Incremental Linker Version 14.28.29213.0
Copyright (C) Microsoft Corporation. All rights reserved.
/out:main.exe
main.obj
C:\Temp>main.exe
Expected behavior
3 compile time errors
STL version
Microsoft Visual Studio Community 2019 Preview Version 16.8.0 Preview 2.0
Additional context
Skipped libcxx test
STL/tests/libcxx/expected_results.txt
Lines 583 to 584 in 06827fe
| # STL bug: string_view doesn't enforce "non-array trivial standard-layout", related to LWG-3034. | |
| std/strings/string.view/char.bad.fail.cpp:0 FAIL |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingfixedSomething works now, yay!Something works now, yay!