42School / norminette

Official 42 norminette
MIT License
944 stars 139 forks source link

ruined on __attribute__((noreturn)) #344

Open mjy9088 opened 2 years ago

mjy9088 commented 2 years ago

Describe the bug

ruined on __attribute__((noreturn))

Erroneous code

/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_exit.h                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: Juyeong Maing <jmaing@student.42seoul.kr>  +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/05/02 14:10:15 by Juyeong Maing     #+#    #+#             */
/*   Updated: 2022/07/31 15:36:07 by Juyeong Maing    ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef FT_EXIT_H
# define FT_EXIT_H

# include <stdlib.h>

typedef void    (*t_ft_exit_cleanup_function)();

# ifdef __GNUC__

__attribute__((noreturn))

# endif

int ft_exit(signed char status);
void    ft_set_exit_handler(void (*cleanup)());

# endif

Additional infos

Additional context

to suppress error Non-void function does not return a value in all control paths

static int  key_press(int keycode, void *param)
{
    (void)param;
    if (keycode == KEY_ESC)
        ft_exit(EXIT_SUCCESS);
    return (0);
}

static int  fdf_exit(int unused, void *param)
{
    (void)unused;
    (void)param;
    ft_exit(EXIT_SUCCESS);
}

correct code:

/* ************************************************************************** */
/*                                                                            */
/*                                                        :::      ::::::::   */
/*   ft_exit.h                                          :+:      :+:    :+:   */
/*                                                    +:+ +:+         +:+     */
/*   By: Juyeong Maing <jmaing@student.42seoul.kr>  +#+  +:+       +#+        */
/*                                                +#+#+#+#+#+   +#+           */
/*   Created: 2022/05/02 14:10:15 by Juyeong Maing     #+#    #+#             */
/*   Updated: 2022/07/31 15:36:07 by Juyeong Maing    ###   ########.fr       */
/*                                                                            */
/* ************************************************************************** */

#ifndef FT_EXIT_H
# define FT_EXIT_H

# include <stdlib.h>

typedef void    (*t_ft_exit_cleanup_function)();

# ifdef __GNUC__

__attribute__((noreturn))

# else if __STDC_VERSION__  > 201703L

[[noreturn]]

# endif

int     ft_exit(signed char status); // here
void    ft_set_exit_handler(void (*cleanup)());

#endif // here
matthieu42Network commented 1 year ago

duplicate #316