Git Product home page Git Product logo

source_location's Introduction

source_location

cross-platform pre c++20 source_location

It uses :

#include <source_location>

or

#include <experimental/source_location>

if they are available.

Builds

Linux Clang Linux GCC MacOS Clang MacOS GCC Windows M2sys Windows MSVC
Github Linux Clang Linux GCC MacOS Clang MacOS GCC Windows MSYS2 Windows MSVC

Example

#include <iostream>
#include <source_location/source_location.hpp>

int main()
{
   source_location loc(source_location::current());
   std::cout << loc.file_name() << std::endl;
   std::cout << loc.function_name() << std::endl;
   std::cout << loc.line() << std::endl;
}

Tests

  • On Linux :
    • gcc-9 : c++98, c++11, c++17, c++20
    • gcc-10 : c++98, c++11, c++17, c++20
    • clang-10 : c++98, c++11, c++17, c++20
    • clang-11 : c++98, c++11, c++17, c++20
  • On MacOS :
    • gcc-9 : c++98, c++11, c++17, c++20
    • gcc-10 : c++98, c++11, c++17, c++20
    • gcc-11 : c++98, c++11, c++17, c++20
    • clang-12 : c++98, c++11, c++17, c++20
  • On Windows :
    • MSVC 19.28.29915.0 : c++98, c++11, c++17, c++20
    • MSYS2 GNU 10.2.0 : c++98, c++11, c++17, c++20
    • MSYS2 Clang 12.0.0 : c++98, c++11, c++17, c++20

source_location's People

Contributors

dependabot[bot] avatar flagarde avatar jmmut avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

source_location's Issues

function with source_location::curent() as argument cannot be in global space in MSVC

#include <iostream>
#include <source_location/source_location.hpp>

source_location src_clone(source_location a = source_location::current())
{
    return a;
}

int main()
{
   auto s2 = src_clone();          // location should point here 
   std::cout
        << s2.line() << ' ' << s2.function_name() << '\n';
}

generate a C2457 error in MSVC https://docs.microsoft.com/en-us/cpp/error-messages/compiler-errors-1/compiler-error-c2457?view=msvc-170

Custom implementation gives incorrect location when used in a default argument (at least in Mac+clang)

Hi, thanks for the code, it's great to have this working cross-compiler cross-platform.

However, I noticed that the custom implementation you added doesn't give the expected call site location when used like this:
(example code simplified from https://en.cppreference.com/w/cpp/utility/source_location/current)

#include <iostream>
#include "source_location/source_location.hpp"

source_location src_clone(source_location a = source_location::current())
{
    return a;
}

int main()
{
    auto s2 = src_clone();          // location should point here 
    std::cout
        << s2.line() << ' ' << s2.function_name() << '\n';
}

I tried like this in Mac with Clang12:

$ clang++ -std=c++11 test.cpp 
test.cpp:5:64: warning: predefined identifier is only valid inside function [-Wpredefined-identifier-outside-function]
source_location src_clone(source_location a = source_location::current())
                                                               ^
./source_location/source_location.hpp:64:60: note: expanded from macro 'current'
#define current(args...) current( __LINE__ , 0, __FILE__ , __PRETTY_FUNCTION__ )
                                                           ^
1 warning generated.


$ ./a.out 
4 top level

Instead of "4 top level" I would expect "11 main".

I understand it might not be possible to give the call site location without compiler support (I can't think of a way to make it work) but I was wondering if you are aware of this and if your tool is working as you expected, as there is no mention to this in the readme and I imagine this is the main use case for source_location to avoid littering call site user code.

Your tool is still useful despite this. Thanks again.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.