Given a gcc.Location, get the source line as a string (without trailing whitespace or newlines)

class gcc.Location

Wrapper around GCC’s location_t, representing a location within the source code. Use gccutils.get_src_for_loc() to get at the line of actual source code.

The output from __repr__ looks like this:

gcc.Location(file='./src/test.c', line=42)

The output from__str__ looks like this:


(string) Name of the source file (or header file)


(int) Line number within source file (starting at 1, not 0)


(int) Column number within source file (starting at 1, not 0)


(bool) This attribute flags locations that are within a system header file. It may be of use when writing custom warnings, so that you can filter out issues in system headers, leaving just those within the user’s code:

# Don't report on issues found in system headers:
if decl.location.in_system_header:
offset_column(self, offset)

Generate a new gcc.Location based on the caret location of this location, offsetting the column by the given amount.

From GCC 6 onwards, these values can represent both a caret and a range, e.g.:

a = (foo && bar)
__init__(self, caret, start, finish)

Construct a location, using the caret location of caret as the caret, and the start/finish of start and finish respectively:

compound_loc = gcc.Location(caret, start, finish)

(gcc.Location) The caret location within this location. In the above example, the caret is on the first ‘&’ character.


(gcc.Location) The start location of this range. In the above example, the start is on the opening parenthesis.


(gcc.Location) The finish location of this range. In the above example, the finish is on the closing parenthesis.

class gcc.RichLocation

Wrapper around GCC’s rich_location, representing one or more locations within the source code, and zero or more fix-it hints.


gcc.RichLocation is only available from GCC 6 onwards

add_fixit_replace(self, new_content)

Add a fix-it hint, suggesting replacement of the content covered by range 0 of the rich location with new_content.