Skip to content

Commit

Permalink
AK: Use direct-list-initialization for Vector::empend() (SerenityOS#4564
Browse files Browse the repository at this point in the history
)

clang trunk with -std=c++20 doesn't seem to properly look for an
aggregate initializer here when the type being constructed is a simple
aggregate (e.g. `struct Thing { int a; int b; };`). This template fails
to compile in a usage added 12/16/2020 in `AK/Trie.h`.

Both forms of initialization are supposed to call the
aggregate-initializers but direct-list-initialization delegating to
aggregate initializers is a new addition in c++20 that might not be
implemented yet.
  • Loading branch information
lanza committed Dec 27, 2020
1 parent 1867c92 commit d1891f6
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion AK/Vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class Vector {
void empend(Args&&... args)
{
grow_capacity(m_size + 1);
new (slot(m_size)) T(forward<Args>(args)...);
new (slot(m_size)) T { forward<Args>(args)... };
++m_size;
}

Expand Down
4 changes: 2 additions & 2 deletions Kernel/FileSystem/Ext2FileSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1433,8 +1433,8 @@ KResult Ext2FS::create_directory(InodeIdentifier parent_id, const String& name,
#endif

Vector<Ext2FSDirectoryEntry> entries;
entries.empend(".", inode->identifier(), EXT2_FT_DIR);
entries.empend("..", parent_id, EXT2_FT_DIR);
entries.empend(".", inode->identifier(), static_cast<u8>(EXT2_FT_DIR));
entries.empend("..", parent_id, static_cast<u8>(EXT2_FT_DIR));

bool success = static_cast<Ext2FSInode&>(*inode).write_directory(entries);
ASSERT(success);
Expand Down
4 changes: 2 additions & 2 deletions Libraries/LibRegex/RegexByteCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class ByteCode : public Vector<ByteCodeValueType> {
ByteCode bytecode;

bytecode.empend(static_cast<ByteCodeValueType>(OpCodeId::Compare));
bytecode.empend(1); // number of arguments
bytecode.empend(static_cast<u64>(1)); // number of arguments

ByteCode arguments;

Expand All @@ -209,7 +209,7 @@ class ByteCode : public Vector<ByteCodeValueType> {
ByteCode bytecode;

bytecode.empend(static_cast<ByteCodeValueType>(OpCodeId::Compare));
bytecode.empend(1); // number of arguments
bytecode.empend(static_cast<u64>(1)); // number of arguments

ByteCode arguments;

Expand Down
2 changes: 1 addition & 1 deletion Services/LookupServer/DNSRequest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include <ctype.h>
#include <stdlib.h>

#define C_IN 1
const u16 C_IN = 1;

DNSRequest::DNSRequest()
: m_id(arc4random_uniform(UINT16_MAX))
Expand Down

0 comments on commit d1891f6

Please sign in to comment.