Skip to content

Instantly share code, notes, and snippets.

@ryb-ableton
Created April 15, 2020 11:59
Show Gist options
  • Save ryb-ableton/1805b61e2d0976de4ba04c2aa2f5992b to your computer and use it in GitHub Desktop.
Save ryb-ableton/1805b61e2d0976de4ba04c2aa2f5992b to your computer and use it in GitHub Desktop.
libc++ type_index uniqueness bug
#!/bin/bash
clang++ -std=c++11 -stdlib=libc++ tu1.cpp tu2.cpp main.cpp -o test
./test
if [ $? -eq 0 ]
then
echo "Success"
exit 0
else
echo "Failure"
exit 1
fi
#include <vector>
#include <typeindex>
extern std::vector<std::type_index> registry;
void register1();
void register2();
#include "common.hpp"
#include <cassert>
std::vector<std::type_index> registry;
int main()
{
register1();
register2();
assert(registry.size() == 2);
assert(registry[0] != registry[1]);
}
#include "common.hpp"
namespace
{
struct A
{
bool x;
};
}
void register1()
{
registry.emplace_back(std::type_index{typeid(A)});
}
#include "common.hpp"
namespace
{
struct A
{
int x, y;
};
}
void register2()
{
registry.emplace_back(std::type_index{typeid(A)});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment