import tempfile


def has_flag(compiler, flagname):
    """Return a boolean indicating whether a flag name is supported on
    the specified compiler.
    """

    with tempfile.NamedTemporaryFile("w", suffix=".cpp") as f:
        print("Testing for flag %s" % (flagname))
        f.write("int main (int argc, char **argv) { return 0; }")
        try:
            compiler.compile([f.name], extra_postargs=[flagname])
        except Exception as e:
            print(e)
            return False
    return True