osmcode / libosmium

Fast and flexible C++ library for working with OpenStreetMap data.
https://osmcode.org/libosmium/
Boost Software License 1.0
472 stars 114 forks source link

compiler error #365

Closed betsch85 closed 1 year ago

betsch85 commented 1 year ago

What version of libosmium are you using?

2.20.0

What operating system and compiler are you using?

MSVC 2022, tried with /std=c++14, /std=c++17 and /std=c++20

What did you do exactly?

trying to compile code from the manual (https://osmcode.org/libosmium/manual.html#working-with-relations)

class MyManager : public osm::relations::RelationsManager<MyManager, true, true, false>
{
public:
    bool new_relation(const osm::Relation& relation) noexcept
    {
        std::cout << "new_relation\n";
        return true;
    }

    bool new_member(const osm::Relation, const osm::RelationMember, std::size_t) noexcept
    {
        std::cout << "new_member\n";
        return true;
    }

    void complete_relation(const osm::Relation& relation)
    {
        std::cout << "ccomplete_relation\n";
        for (const auto& member : relation.members()) 
        {
            if (member.ref() != 0) 
            {
                const osm::OSMObject* obj = this->get_member_object(member);

                const osm::Node* node = this->get_member_node(member.ref());
                const osm::Way* way = this->get_member_way(member.ref());
                const osm::Relation* relation = this->get_member_relation(member.ref());
            }
        }
    }
};
int main(int argc, char* argv[]) {
    // You'll need some OSM input file
    osmium::io::File input_file{argv[1]};

    // Instantiate your manager class
    MyManager manager;

    // First pass through the file
    osmium::relations::read_relations(input_file, manager);

    // Second pass through the file
    osmium::io::Reader reader{input_file};
    osmium::apply(reader, manager.handler());

    // Access data in output buffer
    osmium::memory::Buffer buffer = manager.read(); // fyi, the variable name is missing in the manual
}

if it is wrong to use MyManager as the class name and the first template param please let me know because its (kind of) unclear from the manual what to use here (uses YourManager and YourClass)

hint: it compiles if I remove the instantiation from the class in main

What did you expect to happen?

code compiles without errors

What did happen instead?

1>D:\Code\vcpkg\installed\x64-windows-static\include\osmium\relations\relations_manager.hpp(494,25): error C2280: "osmium::RelationMember::RelationMember(const osmium::RelationMember &)" : Es wurde versucht, auf eine gelöschte Funktion zu verweisen
1>D:\Code\vcpkg\installed\x64-windows-static\include\osmium\osm\relation.hpp(104,9): message : Siehe Deklaration von "osmium::RelationMember::RelationMember"
1>D:\Code\vcpkg\installed\x64-windows-static\include\osmium\osm\relation.hpp(104,9): message : "osmium::RelationMember::RelationMember(const osmium::RelationMember &)": Die Funktion wurde explizit gelöscht.
1>D:\Code\vcpkg\installed\x64-windows-static\include\osmium\relations\relations_manager.hpp(488,1): message : beim Kompilieren der Klasse Vorlage-Memberfunktion "void osmium::relations::RelationsManager<FMRelationsManager,true,true,false,true>::relation(const osmium::Relation &)"
1>D:\Code\vcpkg\installed\x64-windows-static\include\osmium\visitor.hpp(69,37): message : Siehe Verweis auf die gerade kompilierte Instanziierung "void osmium::relations::RelationsManager<FMRelationsManager,true,true,false,true>::relation(const osmium::Relation &)" der Funktions-Vorlage.
joto commented 1 year ago

It is really hard to debug something when you are only giving us code snippets and error messages that don't fit to those snippets with line numbers that we can't see where they are coming from. The code refers to MyManager and YourManager. In the error message it is FMRelationsManager.

Your code says true, true, false, which means you are not interested in relations (the last false). But you are still asking for relation members (this->get_member_relation(member.ref());) which doesn't make much sense. Other than that I can't see anything wrong with the code immediately (except that std::cout << ... is not noexcept so those functions shouldn't be, but that's not the source of the error you are getting here). There might well be something wrong with the example code, you already found the problem with the missing variable.

Can you give us the complete code that you are using?

betsch85 commented 1 year ago

It is really hard to debug something when you are only giving us code snippets and error messages that don't fit to those snippets with line numbers that we can't see where they are coming from. The code refers to MyManager and YourManager. In the error message it is FMRelationsManager.

fixed

Your code says true, true, false, which means you are not interested in relations (the last false). But you are still asking for relation members (this->get_member_relation(member.ref());) which doesn't make much sense. Other than that I can't see anything wrong with the code immediately (except that std::cout << ... is not noexcept so those functions shouldn't be, but that's not the source of the error you are getting here). There might well be something wrong with the example code, you already found the problem with the missing variable.

Can you give us the complete code that you are using?

I don't have access to the full source right now but you should be able to use the two code snippets from the manual and should get the same error. The compiler error is in a libosmium header, not in my own code

I also tried it with true, true, true, but even if the last one is false, the function just shouldn't be called, there shouldn't be a compilation error

If I comment out this line osmium::relations::read_relations(input_file, manager); the code compiles, so it seems like passing manager to read_relations() calls the copy constructor of RelationMember which ist marked as = deleted

betsch85 commented 1 year ago

I think I just found my error, I removed the parameter comments of bool new_member(const osm::Relation, const osm::RelationMember, std::size_t) noexcept and it seems I accidentially removed the &, which would result in passing a copy without a copy constructor, my bad

I'll close this issue later today when I verified my assumption

betsch85 commented 1 year ago

yup, that was it

thanks and sorry :)